By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,667 Members | 1,656 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,667 IT Pros & Developers. It's quick & easy.

How to define a delegate that will have the form a property?

P: n/a
I wand to define a delegate that will have the form a property and not a
method.

Let say I have a property:

public int myProp
{
get { return 0; }
set {}
}

And I want to have a delegate that will take this property as the handler.

Is it possible?
How do I do that?

--
Regards
Sharon G.
Nov 16 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Sharon,

I don't think it's possible.

Why do you need that? Can you please tell us what are you going to do with
the delegate and maybe we can come out with a workaround.

Alexander

"Sharon" <Sh****@discussions.microsoft.com> wrote in message
news:05**********************************@microsof t.com...
I wand to define a delegate that will have the form a property and not a
method.

Let say I have a property:

public int myProp
{
get { return 0; }
set {}
}

And I want to have a delegate that will take this property as the handler.

Is it possible?
How do I do that?

--
Regards
Sharon G.

Nov 16 '05 #2

P: n/a
Well, My application has a class (lets call it myClass) that hold some
properties.
The application also has a Remoting object that hold some delegates that
through them distance users can invoke the myClass properties.

But if the delegates can not point to a properties, then I need to warp the
myClass properties with Get and Set functions that make the property obsolete.

So I wish to keep on using the properties, but the delegates disturbs me
with that.
Any ideas?

-----------
Regards
Sharon G.
Nov 16 '05 #3

P: n/a
This isn't a simple topic and I don't quite comprehend your design... Can
you please show us a pseudo-code how you create your delegates and obtain a
reference to the remote object?

Although it might be completely irrelevant to what you are doing, but if you
inherit your class directly or indirectly from MarshalByRefObject remote
user will be able to invoke the object properties.

Alexander

"Sharon" <Sh****@discussions.microsoft.com> wrote in message
news:49**********************************@microsof t.com...
Well, My application has a class (lets call it myClass) that hold some
properties.
The application also has a Remoting object that hold some delegates that
through them distance users can invoke the myClass properties.

But if the delegates can not point to a properties, then I need to warp
the
myClass properties with Get and Set functions that make the property
obsolete.

So I wish to keep on using the properties, but the delegates disturbs me
with that.
Any ideas?

-----------
Regards
Sharon G.

Nov 16 '05 #4

P: n/a
OK, here is a code show the trouble:

public delegate void SomeSetEventHandler(int arg);
public delegate int SomeGetEventHandler();

public class RemoteObj : MarshalByRefObject
{
public event SomeSetEventHandler SomeSetHandler;
public event SomeGetEventHandler SomeGetHandler;

public int RemoteProp
{
set { SomeSetHandler(value); }
get { return SomeGetHandler(); }
}
}

public class RegularClass
{
private int m_Memeber = 0;

public RegularClass()
{
// Getting a reference to the local RemoteObj... RemoteObjInstance

RemoteObjInstance.SomeSetHandler += new
SomeSetEventHandler(this.ClassPropSetWaraper);
RemoteObjInstance.SomeGetHandler += new
SomeGetEventHandler(this.ClassPropGetWaraper);
}

// I want to have only this property !
public int RegularClassProp
{
set { m_Memeber = value; }
get { return m_Memeber; }
}

// But I must add also a warper set and get method, like this Set method.
public void ClassPropSetWaraper(int arg)
{
RegularClassProp = arg;
}

// And this Get method !!!
public int ClassPropGetWaraper()
{
return RegularClassProp;
}
}

So you see, I want to avoid the double delegate declaration + the double
event declaration + the two warping set and get method. all of this is
because the delegate can not point to a class property.

Nov 16 '05 #5

P: n/a
I think I got it now.

Alas, you'll need those extra two methods...

What I can suggest is to get rid of m_Member variable if possible. Just
delegate calls to RegularClassProp to an instance of RemoteObj:

public int RegularClassProp
{
set { remoteObjInstance.RemoteProp = value; }
get { return remoteObjInstance.RemoteProp; }
}

This way you don't need to syncronize values in two fields.

HTH,
Alexander

"Sharon" <Sh****@discussions.microsoft.com> wrote in message
news:F7**********************************@microsof t.com...
OK, here is a code show the trouble:

public delegate void SomeSetEventHandler(int arg);
public delegate int SomeGetEventHandler();

public class RemoteObj : MarshalByRefObject
{
public event SomeSetEventHandler SomeSetHandler;
public event SomeGetEventHandler SomeGetHandler;

public int RemoteProp
{
set { SomeSetHandler(value); }
get { return SomeGetHandler(); }
}
}

public class RegularClass
{
private int m_Memeber = 0;

public RegularClass()
{
// Getting a reference to the local RemoteObj... RemoteObjInstance

RemoteObjInstance.SomeSetHandler += new
SomeSetEventHandler(this.ClassPropSetWaraper);
RemoteObjInstance.SomeGetHandler += new
SomeGetEventHandler(this.ClassPropGetWaraper);
}

// I want to have only this property !
public int RegularClassProp
{
set { m_Memeber = value; }
get { return m_Memeber; }
}

// But I must add also a warper set and get method, like this Set method.
public void ClassPropSetWaraper(int arg)
{
RegularClassProp = arg;
}

// And this Get method !!!
public int ClassPropGetWaraper()
{
return RegularClassProp;
}
}

So you see, I want to avoid the double delegate declaration + the double
event declaration + the two warping set and get method. all of this is
because the delegate can not point to a class property.

Nov 16 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.