Enum values for Office interop via dynamic object

南楼画角 提交于 2019-12-02 03:29:09

问题


I am using COM interop for Word automation within my Silverlight-Ouf-Of-Browser application. This means that I can't reference COM directly but instead I rely on dynamic.

Now I would like to call the following method:

Range.Collapse(WdCollapseDirection direction).

How do I find out what values are mapped to the individual enum values (e.g.does wdCollapseEnd have a value of 1 or 2)?

Kind regards!

PS: For further info on the method signature see http://msdn.microsoft.com/de-de/library/microsoft.office.interop.word.range.collapse


回答1:


Tools like Reflector make that fairly simple. You could even use ILDASM that comes with part of the .NET Framework.

You can load the Primary Interop Assembly with either of those two tools. Reflector shows the C# source as:

public enum WdCollapseDirection
{
    wdCollapseEnd,
    wdCollapseStart
}

Since they have no explicit values, wdCollapseEnd is 0 and wdCollapseStart is 1. We can confirm with the IL view:

.class public auto ansi sealed WdCollapseDirection
    extends [mscorlib]System.Enum
{
    .field public specialname rtspecialname int32 value__

    .field public static literal valuetype Microsoft.Office.Interop.Word.WdCollapseDirection wdCollapseEnd = int32(0)

    .field public static literal valuetype Microsoft.Office.Interop.Word.WdCollapseDirection wdCollapseStart = int32(1)

}

ILDASM shows this:

.field public static literal valuetype Microsoft.Office.Interop.Word.WdCollapseDirection wdCollapseEnd = int32(0x00000000)

If you have a tool like Resharper, doing Ctrl+Q on it directly from within Visual Studio shows this:

You could have a dummy project that you can use to look up the values.

As an additional option, if you use LINQPad you could reference the Word Primary Interop Assembly (Microsoft.Office.Interop.Word - should be in the GAC) and run this:

void Main()
{
    var value = (int) Microsoft.Office.Interop.Word.WdCollapseDirection.wdCollapseStart;
    Console.Out.WriteLine("value = {0}", value);
}


来源:https://stackoverflow.com/questions/7097358/enum-values-for-office-interop-via-dynamic-object

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!