开发者

Enum values for Office interop via dynamic object

开发者 https://www.devze.com 2023-03-28 23:50 出处:网络
I am using COM interop for Word automation within my Silverlight-Ouf-Of-Browser application. This means that I c开发者_JS百科an\'t reference COM directly but instead I rely on dynamic.

I am using COM interop for Word automation within my Silverlight-Ouf-Of-Browser application. This means that I c开发者_JS百科an'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


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:

Enum values for Office interop via dynamic object

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);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消