2011-08-17 79 views
2

我在我的Silverlight-Ouf-Of-Browser應用程序中爲Word自動化使用COM互操作。這意味着我不能直接引用COM,而是依賴於動態。通過動態對象的Office互操作的枚舉值

現在我想調用下面的方法:

Range.Collapse(WdCollapseDirection方向)。

如何找出哪些值映射到單個枚舉值(例如,wdCollapseEnd的值爲1或2)?

親切的問候!

PS:有關方法簽名進一步信息見http://msdn.microsoft.com/de-de/library/microsoft.office.interop.word.range.collapse

回答

2

工具,比如Reflector做出相當簡單。你甚至可以使用.NET Framework的一部分附帶的ILDASM。

您可以使用這兩種工具之一加載主互操作程序集。反射器示出了C#源爲:

public enum WdCollapseDirection 
{ 
    wdCollapseEnd, 
    wdCollapseStart 
} 

由於它們沒有明確的值,wdCollapseEnd是0和wdCollapseStart是1.我們可以與IL視圖確認:

.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示出了這一點:

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

如果您有像Resharper這樣的工具,請按照以下步驟操作:Ctrl + 上。問從Visual Studio中直接顯示了這一點:

enter image description here

你可以有一個虛擬的項目,你可以用它來查找值。

作爲附加選項,如果你使用LINQPad你可以引用字主Interop大會(的Microsoft.Office.Interop.Word - 應在GAC),並運行此:

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

謝謝,看起來像這比我想象的要容易。 – ollifant