Indexers in Managed C++ 
Author Message
 Indexers in Managed C++

Hello!

I'm writing a Managed C++ assembly and using it in a C#
test program.  I can't figure out how to declare an
indexer in MC++ so that C# will recognize it.  I've tried
creating indexed properties called "Item" or "this", but
in C# these appear translated as literal properties with
names of "Item" or "this", but I can't use the bracket
("[]") syntax with them.

When I compare the disassembled IL of a MC++ assembly
with a broken indexer, and a C# assembly with a working
assembly, the only differences are the "hidebysig"
and "specialname" modifiers.  What am I doing wrong?

Thanks!
-- Chris



Mon, 21 Feb 2005 21:02:25 GMT  
 Indexers in Managed C++

Quote:

> I'm writing a Managed C++ assembly and using it in a C#
> test program.  I can't figure out how to declare an
> indexer in MC++ so that C# will recognize it.  I've tried
> creating indexed properties called "Item" or "this", but
> in C# these appear translated as literal properties with
> names of "Item" or "this", but I can't use the bracket
> ("[]") syntax with them.

You have to define the default member with:

        [System::Reflection::DefaultMember("Alrm")]

on the class level.
For example:

  [System::Reflection::DefaultMember("Alrm")]
  public __sealed __gc class AlarmList : public
System::Collections::CollectionBase
  {
     // ...
    __property Alarm* get_Alrm(System::String *AlarmName);
    __property Alarm* get_Alrm(int Index);

    // ...
  };

--
Greetings
  Jochen



Mon, 21 Feb 2005 21:34:18 GMT  
 Indexers in Managed C++
How are we supposted to know this from the MSDN? This is the MSDN entry for
DefualtMember:
DefaultMemberAttribute Class  [C++]
Defines the member of a type that is the default member used by
InvokeMember. The default member is a name given to a type.

-no examples-

As much as I love the .NET framework and still think that most people have
NO IDEA what a .NET language can do just because the microsoft help is
really difficult to extract information from.


Quote:

> > I'm writing a Managed C++ assembly and using it in a C#
> > test program.  I can't figure out how to declare an
> > indexer in MC++ so that C# will recognize it.  I've tried
> > creating indexed properties called "Item" or "this", but
> > in C# these appear translated as literal properties with
> > names of "Item" or "this", but I can't use the bracket
> > ("[]") syntax with them.

> You have to define the default member with:

> [System::Reflection::DefaultMember("Alrm")]

> on the class level.
> For example:

>   [System::Reflection::DefaultMember("Alrm")]
>   public __sealed __gc class AlarmList : public
> System::Collections::CollectionBase
>   {
>      // ...
>     __property Alarm* get_Alrm(System::String *AlarmName);
>     __property Alarm* get_Alrm(int Index);

>     // ...
>   };

> --
> Greetings
>   Jochen



Mon, 21 Feb 2005 23:31:18 GMT  
 Indexers in Managed C++

Quote:

> How are we supposted to know this from the MSDN?

> -no examples-

> As much as I love the .NET framework and still think that most people
> have NO IDEA what a .NET language can do just because the microsoft
> help is really difficult to extract information from.

FULL ACK

--
Greetings
  Jochen



Tue, 22 Feb 2005 13:16:08 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. using Managed dlls from Managed C++

2. managed C++ wrapper around unmanaged C++ classes: causing StackOverflow exception

3. Performance of unmanaged C++ in a managed C++ app

4. Redirected - Managed C++, differences from standard C++

5. Fatal Error C1010 in Mixing Managed C++ and Unmanaged C++ Code

6. Inherit unmanaged c++ classes from .Net platform (managed c++ or c#)

7. C# client crashs when calling into Managed C++ which calls unmanaged c++ function

8. managed c++ vs unmanaged c++

9. How to pass a function pointer from Managed C++ to unmanaged c++

10. Managed C++ and Unmanaged C++ and Inheritance

11. Interoperability UnManaged C++, Managed C++, C#

12. Migrate C++ to Managed C++

 

 
Powered by phpBB® Forum Software