Managed C++ DefaultMemberAttribute Bug

  • Thread starter ahmed alhamed via .NET 247
  • Start date
A

ahmed alhamed via .NET 247

(Type your message here)
Hi, I am trying to write a managed class tha expose
Multiple Indexers Properties To C#, I use the 'DefaultMemberAttribute' Attribute,
but when i use the class from C# I get Strange Compiler Error.
Here Is The Managed C++:

[System::Reflection::DefaultMemberAttribute(S"It")]
public __gc class Dummy
{
public public:
__property Int32 get_It(Int32 I)
{
return str;
}
__property String* get_It(String* str)
{
return str;
}
};

When I Try This C# Client:
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
Dummy.Dummy d = new Dummy.Dummy();
Console.WriteLine(d[4]);
}
}
it run OK, But When I try This:
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
Dummy.Dummy d = new Dummy.Dummy();
Console.WriteLine(d["HH"]);
}
}
The Compiler Give this error:
"error CS1546: Property, indexer, or event '$Item$' is not supported by the language; try directly calling accessor method 'Dummy.Dummy.get_It(string)'"

I Don not if something that i have done is Wrong, Or Something in the
Managed C++ Compiler.

Thanks in Advance.
 
L

Lord2702

You must have not typed or pasted the C++ code properly, when you are
passing an Int32 and getting Int32 the why you are returning str ?

ahmed alhamed via .NET 247 said:
(Type your message here)
Hi, I am trying to write a managed class tha expose
Multiple Indexers Properties To C#, I use the 'DefaultMemberAttribute' Attribute,
but when i use the class from C# I get Strange Compiler Error.
Here Is The Managed C++:

[System::Reflection::DefaultMemberAttribute(S"It")]
public __gc class Dummy
{
public public:
__property Int32 get_It(Int32 I)
{
return str;
}
__property String* get_It(String* str)
{
return str;
}
};

When I Try This C# Client:
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
Dummy.Dummy d = new Dummy.Dummy();
Console.WriteLine(d[4]);
}
}
it run OK, But When I try This:
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
Dummy.Dummy d = new Dummy.Dummy();
Console.WriteLine(d["HH"]);
}
}
The Compiler Give this error:
"error CS1546: Property, indexer, or event '$Item$' is not supported by
the language; try directly calling accessor method
'Dummy.Dummy.get_It(string)'"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top