通过COM互操作露出索引/默认属性 [英] Exposing the indexer / default property via COM Interop

查看:168
本文介绍了通过COM互操作露出索引/默认属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图写在C#中的一个组成部分由传统的ASP,让我访问组件的索引(又名默认属性)。

I am attempting to write a component in C# to be consumed by classic ASP that allows me to access the indexer of the component (aka default property).

例如:

C#组件:

For example:
C# component:

public class MyCollection {
    public string this[string key] {
        get { /* return the value associated with key */ }
    }

    public void Add(string key, string value) {
        /* add a new element */
    }
}

ASP消费者:

ASP consumer:

Dim collection
Set collection = Server.CreateObject("MyCollection ")
Call collection.Add("key", "value")
Response.Write(collection("key")) ' should print "value"

有没有我需要设置,我需要实现一个接口或者我需要做些别的事情的属性?或者,这不是通过COM互操作的可能?

Is there an attribute I need to set, do I need to implement an interface or do I need to do something else? Or this not possible via COM Interop?

的目的是,我试图创建测试双打一些内置的ASP,如请求,这充分利用使用这些默认属性(如的Request.QueryString集合(对象密钥))。另类的建议是值得欢迎的。

The purpose is that I am attempting to create test doubles for some of the built-in ASP objects such as Request, which make use of collections using these default properties (such as Request.QueryString("key")). Alternative suggestions are welcome.

更新:我问一个跟进的问题:<一href=\"http://stackoverflow.com/questions/317759/why-is-the-indexer-on-my-net-component-not-always-accessible-from-vbscript\">Why是对我的.NET组件索引并不总是从VBScript访问?

Update: I asked a follow-up question: Why is the indexer on my .NET component not always accessible from VBScript?

推荐答案

尝试设置属性的DISPID属性为0,因为在这里描述的 MSDN文档

Try setting the DispId attribute of the property to be 0, as described here in the MSDN documentation.

这篇关于通过COM互操作露出索引/默认属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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