CLI Reference Parameter used for CSharp

E

Ed

Hi, dear all,
Here are some questions when I was writing CLI code, which would be
used by C# Project.

1. Reference Parameter
If CLI method have % reference type parameter, which is ref class,
could C Sharp use it?

In CLI code:

ClassA::SetB(ClassB% classB);


In CSharp:

ClassA classA=new ClassA();
ClassB classB=new ClassB();

classA.SetB(ref classB);
// But the build was failed:
// error CS1501: No overload for method 'SetB' takes '2' arguments


So, how can I use this CLI method in CSharp project?
 
G

Guest

Not sure about the "2 arguments" message, but your CLI code should have a hat
in there if ClassB is a ref class:
e.g.,
ClassA::SetB(ClassB ^%classB);
--
David Anton
http://www.tangiblesoftwaresolutions.com
Convert between VB, C#, and C++
Instant C#
Instant VB
Instant C++
C++ to C# Converter
C++ to VB Converter
 
B

Ben Voigt [C++ MVP]

David Anton said:
Not sure about the "2 arguments" message, but your CLI code should have a
hat
in there if ClassB is a ref class:
e.g.,
ClassA::SetB(ClassB ^%classB);

I think the original notation is also possible, C# will just ignore the
modopt() attribute.

I suggest using .NET Reflector to view the public API generated by the
compiler.
 
E

Ed

I think the original notation is also possible, C# will just ignore the
modopt() attribute.

I suggest using .NET Reflector to view the public API generated by the
compiler.

Thank you!
I will have a try. And if "the public API generated by the compiler."
means the assembly code generated by compiler?
If so, it seems more and more tricks should be searched from the
assembly code generated by compiler.
 
B

Ben Voigt [C++ MVP]

Thank you!
I will have a try. And if "the public API generated by the compiler."
means the assembly code generated by compiler?

..NET Reflector can show the signature of each method in any language,
including, for example, C#.
 

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