通过动态对象进行 Office 互操作的枚举值

2024-04-24

我在 Silverlight-Ouf-Of-Browser 应用程序中使用 COM 互操作来实现 Word 自动化。这意味着我不能直接引用 COM,而是依赖于动态。

现在我想调用以下方法:

Range.Collapse(WdCollapseDirection 方向)。

如何找出哪些值映射到各个枚举值(例如 wdCollapseEnd 的值为 1 或 2)?

亲切的问候!

PS:有关方法签名的更多信息,请参阅http://msdn.microsoft.com/de-de/library/microsoft.office.interop.word.range.collapse http://msdn.microsoft.com/de-de/library/microsoft.office.interop.word.range.collapse


类似的工具反射器 http://www.reflector.net/让这变得相当简单。您甚至可以使用 .NET Framework 的一部分附带的 ILDASM。

您可以使用这两个工具之一加载主互操作程序集。 Reflector 将 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 http://msdn.microsoft.com/en-us/library/f7dy01k1(v=VS.100).aspx显示这个:

.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:

您可以有一个可用于查找值的虚拟项目。

作为附加选项,如果您使用LINQPad http://www.linqpad.net/您可以引用 Word Primary Interop Assembly(Microsoft.Office.Interop.Word - 应该在 GAC 中)并运行以下命令:

void Main()
{
    var value = (int) Microsoft.Office.Interop.Word.WdCollapseDirection.wdCollapseStart;
    Console.Out.WriteLine("value = {0}", value);
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

通过动态对象进行 Office 互操作的枚举值 的相关文章

随机推荐