Can't call indexer property
After recompiling the following code with VS 2005 Beta 2, an C# assembly can't calling the indexer. The code sample works fine with VS 2003.//C++:
[System::Reflection::DefaultMember("Parameter")]
public__gcclass NativeObjectConfigurator :public System::Collections::ArrayList
{
public:
__property ParameterInfo* get_Parameter(int index);
__property ParameterInfo* get_Parameter(System::String* name);
};//C#:
NativeObjectConfigurator no = new NativeObjectConfigurator();
ParameterInfo pi = no["ApplFlags"];
error CS1502: The best overloaded method match for 'System.Collections.ArrayList.this[int]' has some invalid arguments
error CS1503: Argument '1': cannot convert from 'string' to 'int'
Hi Jens, it's a while since I did any managed C++, but lets have a go. Digging around in my long term memory, I seem to remember that managed C++ supported classes that had multiple indexers, whereas C# of course supported just the one. I don't know whether the compiler team has tightened this up in the latest version.
Doesn't the default indexer have to be called "Item" in C++?
Does this work? I'd have thought this wouldn't work in C#, don't have an IDE to hand.
| |
NativeObjectConfigurator no = new NativeObjectConfigurator(); ParameterInfo pi = no.Parameter["ApplFlags"];
|
is there any way to pass non default indexers from C++ to C#?
when i tried it I got new methods in C#, like: get_xxx(int index) and set_xxx(int index,object obj)
here is the C++ code:
public ref class MyClass
{
public property System::Object^ xxx[int]
{
System::Object^ get(int index);
void set(int index, System::Object^ obj);
}
}