Declaring indexed property in C++ Class Library

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Index properties in C++ class libraries (.NET) apper as set_ and get_ methods when used in C#
To test this out, I changed the example from section "13.2 Indexed Properties" in MSDN, and placed the Employee and Manager classes in a library. Then I wrote a C# application implement the code from main(). What happens is that everyting works fine except when trying to call the indexed properties

Example
The following line does not work (as it does in C++)
Ed.Report[ Bob.name ] = Bob

But instead the following works
Ed.set_Report( Bob.name, Bob )

This just doesn't look right
 
Index properties in C++ class libraries (.NET) apper as set_ and get_
methods when used in C#.
To test this out, I changed the example from section "13.2 Indexed
Properties" in MSDN, and placed the Employee and Manager classes in a
library. Then I wrote a C# application implement the code from main().
What happens is that everyting works fine except when trying to call the
indexed properties.
Example:
The following line does not work (as it does in C++):
Ed.Report[ Bob.name ] = Bob;

But instead the following works:
Ed.set_Report( Bob.name, Bob );

This just doesn't look right?

Actually, it looks just about right, since C# does not support indexed
properties directly; except for the limited version of it that are indexers.
See http://www.winterdom.com/mcppfaq/archives/000125.html
[/QUOTE]
 
Thanks for solving this mystery Tomas
To complete the example from "13.2 Indexed Properties", I added this before the definition of the Manager class
[System::Reflection::DefaultMemberAttribute(S"Report")

and now the C# implementation is
Ed[ Bob.name ] = Bob

And the set_Report and get_Report methods are not accessible any more

Does VB.NET behave in the same way

Thanks again
-Fin
 
Fin,
Thanks for solving this mystery Tomas.
To complete the example from "13.2 Indexed Properties", I added this
before the definition of the Manager class:
[System::Reflection::DefaultMemberAttribute(S"Report")]

and now the C# implementation is:
Ed[ Bob.name ] = Bob;

And the set_Report and get_Report methods are not accessible any more.

Does VB.NET behave in the same way?

Ahh... got me there, I don't do much VB.NET, so I'm not sure... I think it
actually does support indexed properties, though...
 
Back
Top