1. <tfoot id='Xgf0T'></tfoot>
      1. <legend id='Xgf0T'><style id='Xgf0T'><dir id='Xgf0T'><q id='Xgf0T'></q></dir></style></legend>
      2. <small id='Xgf0T'></small><noframes id='Xgf0T'>

          <bdo id='Xgf0T'></bdo><ul id='Xgf0T'></ul>

        <i id='Xgf0T'><tr id='Xgf0T'><dt id='Xgf0T'><q id='Xgf0T'><span id='Xgf0T'><b id='Xgf0T'><form id='Xgf0T'><ins id='Xgf0T'></ins><ul id='Xgf0T'></ul><sub id='Xgf0T'></sub></form><legend id='Xgf0T'></legend><bdo id='Xgf0T'><pre id='Xgf0T'><center id='Xgf0T'></center></pre></bdo></b><th id='Xgf0T'></th></span></q></dt></tr></i><div id='Xgf0T'><tfoot id='Xgf0T'></tfoot><dl id='Xgf0T'><fieldset id='Xgf0T'></fieldset></dl></div>

        我可以通过 COM 从 VBA 调用 C# 类的静态方法吗?

        Can I call a static method of a C# class from VBA via COM?(我可以通过 COM 从 VBA 调用 C# 类的静态方法吗?)
        <legend id='DpbPR'><style id='DpbPR'><dir id='DpbPR'><q id='DpbPR'></q></dir></style></legend>
          <tbody id='DpbPR'></tbody>

        <i id='DpbPR'><tr id='DpbPR'><dt id='DpbPR'><q id='DpbPR'><span id='DpbPR'><b id='DpbPR'><form id='DpbPR'><ins id='DpbPR'></ins><ul id='DpbPR'></ul><sub id='DpbPR'></sub></form><legend id='DpbPR'></legend><bdo id='DpbPR'><pre id='DpbPR'><center id='DpbPR'></center></pre></bdo></b><th id='DpbPR'></th></span></q></dt></tr></i><div id='DpbPR'><tfoot id='DpbPR'></tfoot><dl id='DpbPR'><fieldset id='DpbPR'></fieldset></dl></div>
      3. <small id='DpbPR'></small><noframes id='DpbPR'>

            <tfoot id='DpbPR'></tfoot>
              <bdo id='DpbPR'></bdo><ul id='DpbPR'></ul>

                  本文介绍了我可以通过 COM 从 VBA 调用 C# 类的静态方法吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  如果我在 C#/.NET 类库中定义一个类,那么通过使其 COM 可见,我可以实例化该类并使用 COM 从 VBA 调用其方法.

                  If I define a class in a C#/.NET class library, then by making it COM visible I can instantiate the class and call its methods from VBA using COM.

                  有没有办法从 VBA 中调用此类的静态方法?

                  Is there any way to call the static methods of such a class from VBA?

                  推荐答案

                  COM不支持静态方法,COM对象的实例不调用静态方法.相反,在您的静态方法上设置 ComVisible(false),然后创建一个实例方法来包装它:

                  COM does not support static methods, and instances of COM objects do not invoke static methods. Instead, set ComVisible(false) on your static method, then make an instance method to wrap it:

                  [ComVisible(true)]
                  public class Foo
                  {
                      [ComVisible(false)]
                      public static void Bar() {}
                  
                      public void BarInst()
                      {
                          Bar();
                      }
                  }
                  

                  或者只是创建方法实例而不是静态的,然后一起忘记静态.

                  Or just make the method instance instead of static and forget static all together.

                  您没有必须将静态方法标记为对 COM 不可见,但它满足一些代码分析工具的要求,这些工具会警告您关于 COM 可见类型的静态方法,并清楚地表明静态方法不打算对 COM 可见.

                  You don't have to mark the static method as not visible to COM, however it satisfies some code analysis tools that would warn you about static methods on COM visible types, and makes it clear that the static method is not intended to be visible to COM.

                  这篇关于我可以通过 COM 从 VBA 调用 C# 类的静态方法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Performance overhead of using attributes in .NET(在 .NET 中使用属性的性能开销)
                  Accessing attribute info from DTE(从 DTE 访问属性信息)
                  c# Hide a property in datagridview with datasource(c#使用数据源隐藏datagridview中的属性)
                  Extract Display name and description Attribute from within a HTML helper(从 HTML 帮助器中提取显示名称和描述属性)
                  How can I force the PropertyGrid to show a custom dialog for a specific property?(如何强制 PropertyGrid 显示特定属性的自定义对话框?)
                  Associate attribute with code generated property in .net(将属性与 .net 中的代码生成属性相关联)
                  • <bdo id='s8BvC'></bdo><ul id='s8BvC'></ul>
                  • <tfoot id='s8BvC'></tfoot>

                      <small id='s8BvC'></small><noframes id='s8BvC'>

                      <legend id='s8BvC'><style id='s8BvC'><dir id='s8BvC'><q id='s8BvC'></q></dir></style></legend>

                              <tbody id='s8BvC'></tbody>
                            <i id='s8BvC'><tr id='s8BvC'><dt id='s8BvC'><q id='s8BvC'><span id='s8BvC'><b id='s8BvC'><form id='s8BvC'><ins id='s8BvC'></ins><ul id='s8BvC'></ul><sub id='s8BvC'></sub></form><legend id='s8BvC'></legend><bdo id='s8BvC'><pre id='s8BvC'><center id='s8BvC'></center></pre></bdo></b><th id='s8BvC'></th></span></q></dt></tr></i><div id='s8BvC'><tfoot id='s8BvC'></tfoot><dl id='s8BvC'><fieldset id='s8BvC'></fieldset></dl></div>