Exposing properties in COM

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

    #1

    Exposing properties in COM

    But if I do this, then later in the code where I'm implementing set and get

    functions

    I'm getting error : Class already contains a definition for 'MyProperty'.

    Probably I'm not implementing set and get the right way.

    Here is my implementation:

    public string MyProperty

    {

    set{ MyProperty = value; }

    get{ MyProperty sDirMask; }

    }

    Obviously, Public string MyProperty is redefinition. Is there any other way

    of doing it ?

    Thanks

    Roman











    "Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard .caspershouse.c om> wrote in

    message news:<##AAFOmkD HA.3504@TK2MSFT NGP11.phx.gbl>. ..
    [color=blue]
    > Prigozhin,[/color]
    [color=blue]
    >[/color]
    [color=blue]
    > When declaring your interface, you can just do this:[/color]
    [color=blue]
    >[/color]
    [color=blue]
    > public interface IMyInterface[/color]
    [color=blue]
    > {[/color]
    [color=blue]
    > string MyProperty {get; set;}[/color]
    [color=blue]
    > }[/color]
    [color=blue]
    >[/color]
    [color=blue]
    > You can choose to omit either get or set to get write-only or[/color]

    read-only
    [color=blue]
    > functionality.[/color]
    [color=blue]
    >[/color]
    [color=blue]
    > Hope this helps.[/color]
    [color=blue]
    >[/color]
    [color=blue]
    >[/color]
    [color=blue]
    > --[/color]
    [color=blue]
    > - Nicholas Paldino [.NET/C# MVP][/color]
    [color=blue]
    > - mvp@spam.guard. caspershouse.co m[/color]
    [color=blue]
    >[/color]
    [color=blue]
    > "Prigozhin Roman" <prigozhinroman @yahoo.com> wrote in message[/color]
    [color=blue]
    > news:u3O2stdkDH A.708@TK2MSFTNG P10.phx.gbl...[/color]
    [color=blue][color=green]
    > > Hi , I have a COM object implemented in C#[/color][/color]
    [color=blue][color=green]
    > > Problem is that my properties ( which defined public in the class ) can[/color][/color]
    [color=blue]
    > not[/color]
    [color=blue][color=green]
    > > be seen from the outside ( When I call COM )[/color][/color]
    [color=blue][color=green]
    > > I can see only functions I defined in class interface.[/color][/color]
    [color=blue][color=green]
    > > If I try to define variables there I get an error : Interfaces can not[/color][/color]
    [color=blue][color=green]
    > > contain variables ( which is understandable ).[/color][/color]
    [color=blue][color=green]
    > > Question. How to expose variables.[/color][/color]
    [color=blue][color=green]
    > >[/color][/color]
    [color=blue][color=green]
    > > Thanks,[/color][/color]
    [color=blue][color=green]
    > > Roman Prigozhin[/color][/color]
    [color=blue][color=green]
    > > P.S[/color][/color]
    [color=blue][color=green]
    > > If you want to suggest implement set and get functions to do that ,[/color][/color]

    please
    [color=blue][color=green]
    > > don't bother, it is an obvious solution.[/color][/color]
    [color=blue][color=green]
    > > I want to know the other way of doing it through definitions.[/color][/color]
    [color=blue][color=green]
    > >[/color][/color]
    [color=blue][color=green]
    > >[/color][/color]
    [color=blue]
    >[/color]
    [color=blue]
    >[/color]


  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: Exposing properties in COM

    Roman,

    Can you post your code? You should not get that.


    --
    - Nicholas Paldino [.NET/C# MVP]
    - mvp@spam.guard. caspershouse.co m

    "Prigozhin Roman" <prigozhinroman @yahoo.com> wrote in message
    news:ej%23wGUnk DHA.3256@tk2msf tngp13.phx.gbl. ..[color=blue]
    > But if I do this, then later in the code where I'm implementing set and[/color]
    get[color=blue]
    >
    > functions
    >
    > I'm getting error : Class already contains a definition for 'MyProperty'.
    >
    > Probably I'm not implementing set and get the right way.
    >
    > Here is my implementation:
    >
    > public string MyProperty
    >
    > {
    >
    > set{ MyProperty = value; }
    >
    > get{ MyProperty sDirMask; }
    >
    > }
    >
    > Obviously, Public string MyProperty is redefinition. Is there any other[/color]
    way[color=blue]
    >
    > of doing it ?
    >
    > Thanks
    >
    > Roman
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    > "Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard .caspershouse.c om> wrote[/color]
    in[color=blue]
    >
    > message news:<##AAFOmkD HA.3504@TK2MSFT NGP11.phx.gbl>. ..
    >[color=green]
    > > Prigozhin,[/color]
    >[color=green]
    > >[/color]
    >[color=green]
    > > When declaring your interface, you can just do this:[/color]
    >[color=green]
    > >[/color]
    >[color=green]
    > > public interface IMyInterface[/color]
    >[color=green]
    > > {[/color]
    >[color=green]
    > > string MyProperty {get; set;}[/color]
    >[color=green]
    > > }[/color]
    >[color=green]
    > >[/color]
    >[color=green]
    > > You can choose to omit either get or set to get write-only or[/color]
    >
    > read-only
    >[color=green]
    > > functionality.[/color]
    >[color=green]
    > >[/color]
    >[color=green]
    > > Hope this helps.[/color]
    >[color=green]
    > >[/color]
    >[color=green]
    > >[/color]
    >[color=green]
    > > --[/color]
    >[color=green]
    > > - Nicholas Paldino [.NET/C# MVP][/color]
    >[color=green]
    > > - mvp@spam.guard. caspershouse.co m[/color]
    >[color=green]
    > >[/color]
    >[color=green]
    > > "Prigozhin Roman" <prigozhinroman @yahoo.com> wrote in message[/color]
    >[color=green]
    > > news:u3O2stdkDH A.708@TK2MSFTNG P10.phx.gbl...[/color]
    >[color=green][color=darkred]
    > > > Hi , I have a COM object implemented in C#[/color][/color]
    >[color=green][color=darkred]
    > > > Problem is that my properties ( which defined public in the class )[/color][/color][/color]
    can[color=blue]
    >[color=green]
    > > not[/color]
    >[color=green][color=darkred]
    > > > be seen from the outside ( When I call COM )[/color][/color]
    >[color=green][color=darkred]
    > > > I can see only functions I defined in class interface.[/color][/color]
    >[color=green][color=darkred]
    > > > If I try to define variables there I get an error : Interfaces can not[/color][/color]
    >[color=green][color=darkred]
    > > > contain variables ( which is understandable ).[/color][/color]
    >[color=green][color=darkred]
    > > > Question. How to expose variables.[/color][/color]
    >[color=green][color=darkred]
    > > >[/color][/color]
    >[color=green][color=darkred]
    > > > Thanks,[/color][/color]
    >[color=green][color=darkred]
    > > > Roman Prigozhin[/color][/color]
    >[color=green][color=darkred]
    > > > P.S[/color][/color]
    >[color=green][color=darkred]
    > > > If you want to suggest implement set and get functions to do that ,[/color][/color]
    >
    > please
    >[color=green][color=darkred]
    > > > don't bother, it is an obvious solution.[/color][/color]
    >[color=green][color=darkred]
    > > > I want to know the other way of doing it through definitions.[/color][/color]
    >[color=green][color=darkred]
    > > >[/color][/color]
    >[color=green][color=darkred]
    > > >[/color][/color]
    >[color=green]
    > >[/color]
    >[color=green]
    > >[/color]
    >
    >[/color]


    Comment

    • Girish Bharadwaj

      #3
      Re: Exposing properties in COM

      Nicholas Paldino [.NET/C# MVP] wrote:
      [color=blue]
      > Roman,
      >
      > Can you post your code? You should not get that.
      >
      >[/color]
      Umm.. Maybe I am confused (happens to me occasionally .. :) )

      using System;

      public interface IMyIntf
      {
      String MyProperty
      {
      get;
      set;
      }
      }


      public class Test: IMyIntf
      {
      public String MyProperty
      {
      get
      {
      return _myProp;
      }

      set
      {
      _myProp = value;
      }

      }

      private string _myProp;

      public static void Main (String[] args)
      {
      Test t = new Test();
      t.MyProperty = "test";
      Console.WriteLi ne(t.MyProperty );
      }
      }

      This seems to work..
      --
      Girish Bharadwaj

      Comment

      • Nicholas Paldino [.NET/C# MVP]

        #4
        Re: Exposing properties in COM

        Girish,

        The original poster did not post the code for the complete class, nor
        did he/she post the interface definition. You are right, it should work,
        but the original poster didn't include those two things and I want to make
        sure that there wasn't something else going on that I couldn't have been
        aware of.


        --
        - Nicholas Paldino [.NET/C# MVP]
        - mvp@spam.guard. caspershouse.co m

        "Girish Bharadwaj" <girishb@nowher e> wrote in message
        news:u7hzLynkDH A.1800@TK2MSFTN GP10.phx.gbl...[color=blue]
        > Nicholas Paldino [.NET/C# MVP] wrote:
        >[color=green]
        > > Roman,
        > >
        > > Can you post your code? You should not get that.
        > >
        > >[/color]
        > Umm.. Maybe I am confused (happens to me occasionally .. :) )
        >
        > using System;
        >
        > public interface IMyIntf
        > {
        > String MyProperty
        > {
        > get;
        > set;
        > }
        > }
        >
        >
        > public class Test: IMyIntf
        > {
        > public String MyProperty
        > {
        > get
        > {
        > return _myProp;
        > }
        >
        > set
        > {
        > _myProp = value;
        > }
        >
        > }
        >
        > private string _myProp;
        >
        > public static void Main (String[] args)
        > {
        > Test t = new Test();
        > t.MyProperty = "test";
        > Console.WriteLi ne(t.MyProperty );
        > }
        > }
        >
        > This seems to work..
        > --
        > Girish Bharadwaj
        >[/color]


        Comment

        Working...