2011-08-17 83 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