473,395 Members | 1,938 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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

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
5 1229
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Clinton Pierce | last post by:
I can create a delegate like this, and everything works fine: class Foo { private delegate void NextPanel(); private NextPanel myself; // And later in a method private void EffStart() {
0
by: Ginno | last post by:
Hello all Within my reports form i have used delegates to allow a crystall reports to generate without holding up the user. The user selects a report from tree view, enters the appropriate...
15
by: Sharon | last post by:
I’m trying to build a generic Publisher-Subscriber that will work over the net, so I’m using the Remoting. I wish that the subscriber user will be notify about the messages sent by the...
6
by: Bill Davidson | last post by:
All: I'd like to create a delegate for a property (as opposed to a method). Can I do this? If so, please teach me the syntactic magic. For example, suppose I have a boolean ready-only...
3
by: Wolfgang Kaml | last post by:
I tried to implement a callback as described in the MSDN Mag article 2003/1 p105ff 'Implementing Callbacks'. I have no idea, of what could be different in my code, but for some reason, I get an...
18
by: **Developer** | last post by:
I always define events with the parameters ByVal sender As Object, ByVal e As EventArgs Even if they are not used. Seems I read someplace that's the thing to do. So I then do:
5
by: han zhiyang | last post by:
Hi. I tried to design a custom web control which can flexibly and dynamicly let the control user ,for example the web page developer, customize its layout codes.This control derives from...
7
by: Ant | last post by:
Hello, Very simple question but one I need clarified. Which part of the statement below is considered the 'delegate'? Is it the 'new System.EventHandler' or the btnAccept_Click? or is it...
5
vanc
by: vanc | last post by:
I read many articles about this problem, but I found out that to pass values between one created form and one is not yet is created is fairly simple, it can be done by assign value to public variable...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.