473,386 Members | 1,819 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,386 software developers and data experts.

How to add additional info to a delegate instance? (mimic java EventListenerProxy)

-
Hi to All,

Is there any trick for adding additional runtime info (for example a string)
to a delegate instance?

I would like to mimic the Java EventListener - EventListenerProxy,
PropertyListener - PropertyListenerProxy
semantics. I can replace the PropertyListener class with a multicast
delegate, let's say PropertyChangeDelegate.
The problem that PropertyListenerProxy should be also a delegate, but it has
an additional string property, which can be set by the subscriber, and
publisher can filter (or anything) by it.

Of course I can mechanically port the Java event handling semantics, but in
this case I can not use the high level
functionality which is out of the box with .NET multicastdelegate, and I
must reimplement it :-(

Any ideas?
Thx for answers

Nov 17 '05 #1
5 2173
AFAIK, there isn't anything in the framework to do this. Doing
something of this nature isn't that hard though. Since you can attach a
delegate to any method that has a matching signature, it would be easy to
create a wrapper that will act as storage for the extra information, and put
the event handler logic in there (along with references to whatever else it
needs).
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"-" <-@hotmail.com> wrote in message
news:OJ*************@TK2MSFTNGP09.phx.gbl...
Hi to All,

Is there any trick for adding additional runtime info (for example a
string) to a delegate instance?

I would like to mimic the Java EventListener - EventListenerProxy,
PropertyListener - PropertyListenerProxy
semantics. I can replace the PropertyListener class with a multicast
delegate, let's say PropertyChangeDelegate.
The problem that PropertyListenerProxy should be also a delegate, but it
has an additional string property, which can be set by the subscriber, and
publisher can filter (or anything) by it.

Of course I can mechanically port the Java event handling semantics, but
in this case I can not use the high level
functionality which is out of the box with .NET multicastdelegate, and I
must reimplement it :-(

Any ideas?
Thx for answers


Nov 17 '05 #2
-
Hi Nicholas,

Thx for your answer.

The problem with the wrapper solution is that the wrapper (or proxy as the
Java implementation calls it) should be itself type compatible with the
contained delegate, with other words, it should be a delegeate also.

This is important because we must put the proxy to the invocation list of
the publisher. (We must Combine it (or +=) to the multicast list.

If we can not do that, then we must reimplement the multicast infrastucture,
which is far more complicated as if looks at first sight.

horo


"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:O7**************@TK2MSFTNGP15.phx.gbl...
AFAIK, there isn't anything in the framework to do this. Doing
something of this nature isn't that hard though. Since you can attach a
delegate to any method that has a matching signature, it would be easy to
create a wrapper that will act as storage for the extra information, and
put the event handler logic in there (along with references to whatever
else it needs).
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"-" <-@hotmail.com> wrote in message
news:OJ*************@TK2MSFTNGP09.phx.gbl...
Hi to All,

Is there any trick for adding additional runtime info (for example a
string) to a delegate instance?

I would like to mimic the Java EventListener - EventListenerProxy,
PropertyListener - PropertyListenerProxy
semantics. I can replace the PropertyListener class with a multicast
delegate, let's say PropertyChangeDelegate.
The problem that PropertyListenerProxy should be also a delegate, but it
has an additional string property, which can be set by the subscriber,
and publisher can filter (or anything) by it.

Of course I can mechanically port the Java event handling semantics, but
in this case I can not use the high level
functionality which is out of the box with .NET multicastdelegate, and I
must reimplement it :-(

Any ideas?
Thx for answers



Nov 17 '05 #3
> The problem with the wrapper solution is that the wrapper (or proxy as the
Java implementation calls it) should be itself type compatible with the
contained delegate, with other words, it should be a delegeate also.


No, you misunderstood the suggestion. Let's say you have a CoreClass
that has a method

void Example(int N)

that you wanted to create a delegate for. Plus, you wanted the
delegate to have access to an extra string. You'd just create a class
like

class Wrapper
{
public Wrapper(CoreClass Core, string ExtraString)
{
this.Core = Core;
this.ExtraString = ExtraString;
}

private CoreClass Core;
private string ExtraString;

public void Example(int N)
{
if (ExtraString == "Do it!") // or whatever
Core.Example(N);
}
}

and pass a delegate to Wrapper.Example instead of CoreClass.Example.

--

www.midnightbeach.com
Nov 17 '05 #4
Horo,

That's the thing, it is type compatable, since you are using the same
delegate type. The delegate is identified by the signature, so you can have
a wrapper of a different type which has a method with the same signature
which is wrapped by the delegate, and then attach that to the event.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"-" <-@hotmail.com> wrote in message
news:Ok*************@TK2MSFTNGP10.phx.gbl...
Hi Nicholas,

Thx for your answer.

The problem with the wrapper solution is that the wrapper (or proxy as the
Java implementation calls it) should be itself type compatible with the
contained delegate, with other words, it should be a delegeate also.

This is important because we must put the proxy to the invocation list of
the publisher. (We must Combine it (or +=) to the multicast list.

If we can not do that, then we must reimplement the multicast
infrastucture, which is far more complicated as if looks at first sight.

horo


"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote
in message news:O7**************@TK2MSFTNGP15.phx.gbl...
AFAIK, there isn't anything in the framework to do this. Doing
something of this nature isn't that hard though. Since you can attach a
delegate to any method that has a matching signature, it would be easy to
create a wrapper that will act as storage for the extra information, and
put the event handler logic in there (along with references to whatever
else it needs).
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"-" <-@hotmail.com> wrote in message
news:OJ*************@TK2MSFTNGP09.phx.gbl...
Hi to All,

Is there any trick for adding additional runtime info (for example a
string) to a delegate instance?

I would like to mimic the Java EventListener - EventListenerProxy,
PropertyListener - PropertyListenerProxy
semantics. I can replace the PropertyListener class with a multicast
delegate, let's say PropertyChangeDelegate.
The problem that PropertyListenerProxy should be also a delegate, but it
has an additional string property, which can be set by the subscriber,
and publisher can filter (or anything) by it.

Of course I can mechanically port the Java event handling semantics, but
in this case I can not use the high level
functionality which is out of the box with .NET multicastdelegate, and I
must reimplement it :-(

Any ideas?
Thx for answers




Nov 17 '05 #5
-
Cool :-)

Thx for you both, Nicholas and Jon.

horo

"Jon Shemitz" <jo*@midnightbeach.com> wrote in message
news:43***************@midnightbeach.com...
The problem with the wrapper solution is that the wrapper (or proxy as
the
Java implementation calls it) should be itself type compatible with the
contained delegate, with other words, it should be a delegeate also.


No, you misunderstood the suggestion. Let's say you have a CoreClass
that has a method

void Example(int N)

that you wanted to create a delegate for. Plus, you wanted the
delegate to have access to an extra string. You'd just create a class
like

class Wrapper
{
public Wrapper(CoreClass Core, string ExtraString)
{
this.Core = Core;
this.ExtraString = ExtraString;
}

private CoreClass Core;
private string ExtraString;

public void Example(int N)
{
if (ExtraString == "Do it!") // or whatever
Core.Example(N);
}
}

and pass a delegate to Wrapper.Example instead of CoreClass.Example.

--

www.midnightbeach.com

Nov 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: N8 | last post by:
I am trying to get an exception to occur and consequently found that when adding a target method to a delegates invocation list, a copy of that object is added instead of a reference to the object....
2
by: Nima | last post by:
The documentation for the Delegate and the MultiCastDelegate classes tell me that when we have a line like: public delegate void CheckAndPrintDelegate(string str); it causes the compiler to...
5
by: Edward Diener | last post by:
The first type to a delegate constructor is obvious. It is a System::Object * . What is the MC++ type of the second argument to the delegate constructor ? In C++ it would be a member function...
3
by: Minh Khoa | last post by:
Please give me more information about delegate and its usage? Why do i use it and when?
4
by: Bill Woodruff | last post by:
< note : this message was sparked in part by comments by David Browne on a previous thread : "inserting an anonymous method as a value in a generic dictionary ?" : David had shown the use of...
11
by: matsi.inc | last post by:
I am looking to make something like a delegate that i can use in my projects but am having a hard time getting started. The behavior I am most interested in is how a delegate changes it's Invoke...
11
by: ohmmega | last post by:
hello world. i would like to implement a class with a timer, witch informs me every second about it's tick. the code works already, but i would like to change a thing (or more). <code> //at...
26
by: raylopez99 | last post by:
Here is a good example that shows generic delegate types. Read this through and you'll have an excellent understanding of how to use these types. You might say that the combination of the generic...
1
by: jadeite100 | last post by:
Hi All: I installed oracle report server 10.1.2.02 I tried the following url and it display the page properly that ask Test run Job: http://xxx/reports/rwwebservice?operation=runJob When I...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.