CLI Reference Parameter used for CSharp

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ed

    #1

    CLI Reference Parameter used for CSharp

    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(Cl assB% 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?

  • =?Utf-8?B?RGF2aWQgQW50b24=?=

    #2
    RE: CLI Reference Parameter used for CSharp

    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(Cl assB ^%classB);
    --
    David Anton
    Source code converters: Convert between C#, C++, Java, and VB with the most accurate and reliable source code converters

    Convert between VB, C#, and C++
    Instant C#
    Instant VB
    Instant C++
    C++ to C# Converter
    C++ to VB Converter


    "Ed" wrote:
    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(Cl assB% 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?
    >
    >

    Comment

    • Ben Voigt [C++ MVP]

      #3
      Re: CLI Reference Parameter used for CSharp


      "David Anton" <DavidAnton@dis cussions.micros oft.comwrote in message
      news:D62D7ADC-1CF5-4F53-AE96-CDAF0FA216EB@mi crosoft.com...
      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(Cl assB ^%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.
      --
      David Anton
      Source code converters: Convert between C#, C++, Java, and VB with the most accurate and reliable source code converters

      Convert between VB, C#, and C++
      Instant C#
      Instant VB
      Instant C++
      C++ to C# Converter
      C++ to VB Converter
      >
      >
      "Ed" wrote:
      >
      >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(C lassB% classB);
      >>
      >>
      >In CSharp:
      >>
      >ClassA classA=new ClassA();
      >ClassB classB=new ClassB();
      >>
      >classA.SetB(re f 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?
      >>
      >>

      Comment

      • Ed

        #4
        Re: CLI Reference Parameter used for CSharp

        On 8 9 , 10 28 , "Ben Voigt [C++ MVP]" <r...@nospam.no spamwrote:
        "David Anton" <DavidAn...@dis cussions.micros oft.comwrote in message
        >
        news:D62D7ADC-1CF5-4F53-AE96-CDAF0FA216EB@mi crosoft.com...
        >
        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(Cl assB ^%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.
        >
        --
        David Anton
        Source code converters: Convert between C#, C++, Java, and VB with the most accurate and reliable source code converters

        Convert between VB, C#, and C++
        Instant C#
        Instant VB
        Instant C++
        C++ to C# Converter
        C++ to VB Converter
        >
        "Ed" wrote:
        >
        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(Cl assB% 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?
        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.


        Comment

        • Ben Voigt [C++ MVP]

          #5
          Re: CLI Reference Parameter used for CSharp

          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#.
          If so, it seems more and more tricks should be searched from the
          assembly code generated by compiler.
          >
          >

          Comment

          Working...