<tfoot id='xD85d'></tfoot>
    1. <legend id='xD85d'><style id='xD85d'><dir id='xD85d'><q id='xD85d'></q></dir></style></legend>

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

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

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

        COM 互操作的通用集合的替代方案是什么?

        时间:2023-10-06

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

              <legend id='FzZXh'><style id='FzZXh'><dir id='FzZXh'><q id='FzZXh'></q></dir></style></legend>
            1. <tfoot id='FzZXh'></tfoot>
                <bdo id='FzZXh'></bdo><ul id='FzZXh'></ul>

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

                  本文介绍了COM 互操作的通用集合的替代方案是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试从 .NET 程序集中返回一组部门,以供 ASP 通过 COM 互操作使用.使用 .NET 我只会返回一个通用集合,例如List<Department>,但泛型似乎不适用于 COM 互操作.那么,我有哪些选择?

                  I am attempting to return a collection of departments from a .NET assembly to be consumed by ASP via COM Interop. Using .NET I would just return a generic collection, e.g. List<Department>, but it seems that generics don't work well with COM Interop. So, what are my options?

                  我想遍历列表并能够按索引访问项目.我应该从 List 继承,实现 IListIList 或其他接口,还是有更好的方法?理想情况下,我宁愿不必为我需要的每种类型的列表实现自定义集合.此外,List[index] 甚至可以与 COM Interop 一起使用吗?

                  I would like to both iterate over the list and be able to access an item by index. Should I inherit from List<Department>, implement an IList, IList<Department> or another interface, or is there a better way? Ideally I would prefer not to have to implement a custom collection for every type of list I need. Also, will List[index] even work with COM Interop?

                  谢谢,迈克

                  public class Department {
                      public string Code { get; private set; }
                      public string Name { get; private set; }
                      // ...
                  }
                  
                  public class MyLibrary {
                      public List<Department> GetDepartments() {
                          // return a list of Departments from the database
                      }
                  }
                  

                  示例 ASP 代码:

                  <%
                  Function PrintDepartments(departments)
                      Dim department
                      For Each department In departments
                          Response.Write(department.Code & ": " & department.Name & "<br />")
                      Next
                  End Function
                  
                  Dim myLibrary, departments
                  Set myLibrary = Server.CreateObject("MyAssembly.MyLibrary")
                  Set departments = myLibrary.GetDepartments()
                  %>
                  <h1>Departments</h1>
                  <% Call PrintDepartments(departments) %>
                  <h1>The third department</h1>
                  <%= departments(2).Name %>
                  

                  相关问题:

                  • 在服务组件上使用通用列表
                  • .NET 中的非泛型集合是否已过时?
                  • 推荐答案

                    经过更多的研究和反复试验,我想我找到了使用 System.Collections.ArrayList 的解决方案.但是,这不适用于按索引获取值.为此,我创建了一个继承自 ArrayList 的新类 ComArrayList,并添加了新方法 GetByIndexSetByIndex.

                    After some more research and trial-and-error, I think I found a solution by using System.Collections.ArrayList. However, this does not work with getting a value by index. To do so, I created a new class ComArrayList that inherits from ArrayList and adds new methods GetByIndex and SetByIndex.

                    public class ComArrayList : System.Collections.ArrayList {
                        public virtual object GetByIndex(int index) {
                            return base[index];
                        }
                    
                        public virtual void SetByIndex(int index, object value) {
                            base[index] = value;
                        }
                    }
                    

                    更新了 .NET 组件 MyLibrary.GetDepartments:

                    public ComArrayList GetDepartments() {
                        // return a list of Departments from the database
                    }
                    

                    更新的 ASP:

                    <h1>The third department</h1>
                    <%= departments.GetByIndex(2).Name %>
                    

                    这篇关于COM 互操作的通用集合的替代方案是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:C#中按位桶形移位的问题 下一篇:跨不同域和不同应用程序(经典 ASP 和 ASP.NET)共享 cookie

                  相关文章

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

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