通过动态对象进行Office互操作的枚举值 [英] Enum values for Office interop via dynamic object

查看:114
本文介绍了通过动态对象进行Office互操作的枚举值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Silverlight-Ouf-Of-Browser应用程序中使用COM interop进行Word自动化.这意味着我不能直接引用COM,而是依靠动态.

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方向).

Range.Collapse(WdCollapseDirection direction).

我如何找出映射到各个枚举值的值(例如wdCollapseEnd的值是1还是2)?

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)?

亲切的问候!

PS:有关方法签名的更多信息,请参见

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

推荐答案

Reflector 之类的工具简单的.您甚至可以使用.NET Framework随附的ILDASM.

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

您可以使用这两个工具中的任何一个来加载Primary Interop Assembly. Reflector将C#源显示为:

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

public enum WdCollapseDirection
{
    wdCollapseEnd,
    wdCollapseStart
}

由于它们没有显式值,因此wdCollapseEnd为0,wdCollapseStart为1.我们可以使用IL视图进行确认:

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 显示如下:

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

如果您拥有Resharper之类的工具,直接在Visual Studio中对其进行 Ctrl + Q 会显示以下内容:

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.

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

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

这篇关于通过动态对象进行Office互操作的枚举值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆