<legend id='6nbWf'><style id='6nbWf'><dir id='6nbWf'><q id='6nbWf'></q></dir></style></legend>
      <bdo id='6nbWf'></bdo><ul id='6nbWf'></ul>
    1. <i id='6nbWf'><tr id='6nbWf'><dt id='6nbWf'><q id='6nbWf'><span id='6nbWf'><b id='6nbWf'><form id='6nbWf'><ins id='6nbWf'></ins><ul id='6nbWf'></ul><sub id='6nbWf'></sub></form><legend id='6nbWf'></legend><bdo id='6nbWf'><pre id='6nbWf'><center id='6nbWf'></center></pre></bdo></b><th id='6nbWf'></th></span></q></dt></tr></i><div id='6nbWf'><tfoot id='6nbWf'></tfoot><dl id='6nbWf'><fieldset id='6nbWf'></fieldset></dl></div>

        <small id='6nbWf'></small><noframes id='6nbWf'>

      1. <tfoot id='6nbWf'></tfoot>

        C# 向 COM 公开类 - 通用集合

        C# exposing class to COM - Generic Collections(C# 向 COM 公开类 - 通用集合)

          <tbody id='0O2e7'></tbody>

          1. <legend id='0O2e7'><style id='0O2e7'><dir id='0O2e7'><q id='0O2e7'></q></dir></style></legend>

              <tfoot id='0O2e7'></tfoot>

              <small id='0O2e7'></small><noframes id='0O2e7'>

                  <bdo id='0O2e7'></bdo><ul id='0O2e7'></ul>

                  <i id='0O2e7'><tr id='0O2e7'><dt id='0O2e7'><q id='0O2e7'><span id='0O2e7'><b id='0O2e7'><form id='0O2e7'><ins id='0O2e7'></ins><ul id='0O2e7'></ul><sub id='0O2e7'></sub></form><legend id='0O2e7'></legend><bdo id='0O2e7'><pre id='0O2e7'><center id='0O2e7'></center></pre></bdo></b><th id='0O2e7'></th></span></q></dt></tr></i><div id='0O2e7'><tfoot id='0O2e7'></tfoot><dl id='0O2e7'><fieldset id='0O2e7'></fieldset></dl></div>
                • 本文介绍了C# 向 COM 公开类 - 通用集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我们有一个用 C# .Net 2.0 编写的小框架,我们想向 COM 公开.

                  We have a small framework written in C# .Net 2.0 that we want to expose to COM.

                  问题是,我们有一些通用类会暴露如下:

                  Problem is, we have some generic classes that would be exposed as the following:

                  interface IOurClass
                  {
                    ReadonlyCollection<IOurListObject> OurCollection
                    {
                      get;
                    }
                  }
                  
                  interface IOurListObject
                  {
                    //Some properties that don't matter
                  }
                  

                  向 COM 公开泛型集合的最佳(或推荐方式)是什么?我们不必支持泛型,我们只需要以某种方式公开 IOurListObject 的集合.

                  What is the best (or recommended way) to expose generic collections to COM? We do not have to support generics, we just need to somehow expose a collection of IOurListObject.

                  我们也希望避免为我们使用的每个集合编写一个新类,但这可能是不可能的.

                  We also would like to avoid having to write a new class for every collection we use, but it may not be possible.

                  推荐答案

                  不可能向 COM 公开泛型集合(或任何其他泛型").

                  It is not possible to expose generic collections (or any other thing that is 'generic') to COM.

                  所以,我建议您在 COM 可见界面中创建一个非泛型属性(或方法).此方法可以返回IOurListObject"项的数组.在你的类中,你可以显式地实现这个方法,这样当你直接在 COM 之外引用对象时,它就不会出现在你的智能感知中.

                  So, I suggest that you create a non-generic property (or method) in your COM-visible interface. This method could return an array of 'IOurListObject' items. In your class, you could implement this method explicitly, so that it does not show up in your intellisense when you refer to the object directly outside COM, for instance.

                  我希望我能说清楚一点.

                  I hope I make myself a bit clear.

                  例子:

                  [ComVisible(true)]
                  public interface IOurClass
                  {
                      IOurListObject[] OurCollection { get; }
                  }
                  
                  public class OurClass : IOurClass
                  {
                      IOurListObject[] IOurClass.OurCollection { get { return OurCollection.ToArray();} }
                  
                      public ReadOnlyCollection<IOurListObject> OurCollection { ... }
                  }
                  

                  这篇关于C# 向 COM 公开类 - 通用集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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 中的代码生成属性相关联)
                    <tbody id='sNed7'></tbody>
                      <bdo id='sNed7'></bdo><ul id='sNed7'></ul>
                    • <tfoot id='sNed7'></tfoot>
                        <legend id='sNed7'><style id='sNed7'><dir id='sNed7'><q id='sNed7'></q></dir></style></legend>
                        <i id='sNed7'><tr id='sNed7'><dt id='sNed7'><q id='sNed7'><span id='sNed7'><b id='sNed7'><form id='sNed7'><ins id='sNed7'></ins><ul id='sNed7'></ul><sub id='sNed7'></sub></form><legend id='sNed7'></legend><bdo id='sNed7'><pre id='sNed7'><center id='sNed7'></center></pre></bdo></b><th id='sNed7'></th></span></q></dt></tr></i><div id='sNed7'><tfoot id='sNed7'></tfoot><dl id='sNed7'><fieldset id='sNed7'></fieldset></dl></div>
                      • <small id='sNed7'></small><noframes id='sNed7'>