【发布时间】:2008-11-18 16:23:35
【问题描述】:
我正在尝试用 C# 编写一个组件,供经典 ASP 使用,它允许我访问组件的索引器(也称为默认属性)。
例如:
C# 组件:
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 消费者:
Dim collection
Set collection = Server.CreateObject("MyCollection ")
Call collection.Add("key", "value")
Response.Write(collection("key")) ' should print "value"
是否有我需要设置的属性,我需要实现接口还是需要做其他事情?或者这不能通过 COM 互操作实现?
目的是我试图为一些内置的 ASP 对象(例如 Request)创建测试替身,这些对象使用使用这些默认属性(例如 Request.QueryString("key"))的集合。欢迎提供其他建议。
更新:我问了一个后续问题:Why is the indexer on my .NET component not always accessible from VBScript?
【问题讨论】:
标签: c# collections asp-classic vbscript com-interop