C#COM DLL属性的非泛型索引器
我正在尝试创建一个对象数组,其中的索引可以在Microsoft Access中公开。我已经找到了如何创建索引器类,但由于它是泛型的,所以该属性没有在Access VBA中公开。更具体地说,我正在转换一个与Access一起工作的VB.NET COM DLL,这是我试图转换的字符串数组属性代码:C#COM DLL属性的非泛型索引器,c#,vb.net,vba,generics,dll,C#,Vb.net,Vba,Generics,Dll,我正在尝试创建一个对象数组,其中的索引可以在Microsoft Access中公开。我已经找到了如何创建索引器类,但由于它是泛型的,所以该属性没有在Access VBA中公开。更具体地说,我正在转换一个与Access一起工作的VB.NET COM DLL,这是我试图转换的字符串数组属性代码: Public Shared _ReportParameters(0 To 9) As String Public Property ReportParameters(Optional ind
Public Shared _ReportParameters(0 To 9) As String
Public Property ReportParameters(Optional index As Integer = Nothing) As String
Get
Return _ReportParameters(index)
End Get
Set(ByVal Value As String)
_ReportParameters(index) = Value
End Set
End Property
下面是我转换为C#的代码,它使用的索引器类不能在DLL中公开:
public static string[] _ReportParameters = new string[10];
public Indexer<string> ReportParameters
{
get
{
return _ReportParameters.GetIndexer();
}
}
publicstaticstring[]\u ReportParameters=新字符串[10];
公共索引器报表参数
{
得到
{
返回_ReportParameters.GetIndexer();
}
}
有什么想法吗?您发布的VB.NET代码中最接近C的是:
class Thing
{
public static string[] _ReportParameters = new string[10];
public string[] ReportParameters { get { return _ReportParameters; } }
}
它被用作
var thing = new Thing();
var result = thing.ReportParameters[0];
thing.ReportParameters[1] = "Test";
但是,索引器的编写方式如下:
class Thing
{
public static string[] _ReportParameters = new string[10];
public string this[int index]
{
get
{
return _ReportParameters[index];
}
set
{
_ReportParameters[index] = value;
}
}
}
它被用作
var thing = new Thing();
var result = thing[0];
thing[1] = "Test";
我还应该注意,实例属性返回静态(和公共)字段有点奇怪。