Exposing properties in COM

P

Prigozhin Roman

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












message news: said:
Prigozhin,
When declaring your interface, you can just do this:
public interface IMyInterface

string MyProperty {get; set;}

You can choose to omit either get or set to get write-only or
read-only
functionality.

Hope this helps.

- Nicholas Paldino [.NET/C# MVP]
 
N

Nicholas Paldino [.NET/C# MVP]

Roman,

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


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Prigozhin Roman said:
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












message news: said:
Prigozhin,
When declaring your interface, you can just do this:
public interface IMyInterface

string MyProperty {get; set;}

You can choose to omit either get or set to get write-only or
read-only
functionality.

Hope this helps.

- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)
can
 
G

Girish Bharadwaj

Nicholas said:
Roman,

Can you post your code? You should not get that.
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.WriteLine(t.MyProperty);
}
}

This seems to work..
 
N

Nicholas Paldino [.NET/C# MVP]

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]
- (e-mail address removed)

Girish Bharadwaj said:
Nicholas said:
Roman,

Can you post your code? You should not get that.
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.WriteLine(t.MyProperty);
}
}

This seems to work..
 

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