473,543 Members | 1,999 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Delegate.Create Delegate equivalent in NetCF.

Hi,

I need Delegate.Create Delegate method equivalent in compact
framework.

Best regards,
Klaudiusz
Jul 24 '08 #1
9 3029
On 24 Lip, 12:14, Klaudiusz Bryja <bryja_klaudi.. .@poczta.fmwrot e:
Hi,

I need Delegate.Create Delegate method equivalent in compact
framework.

Best regards,
Klaudiusz
Sorry I send before finish. In full framework this method create
delegate of proper type (e.g. KeyEventHandler , EventHandler).
Jul 24 '08 #2
It is there in 3.5; in 2.0 you can invoke the method (etc) directly via
Invoke, or if you absolutely *need* a delegate perhaps use an anonymous
method (and capture) to create it, i.e.

(where getter is the instance of a Getter delegate - think Func<,>)

#if CF2
getter = delegate(TEntit y instance) {
return (TValue)propert y.GetValue(inst ance, null);
};
#else
getter = (Getter)Delegat e.CreateDelegat e(
typeof(Getter), null, method);
#endif

A bit hacky, but it should work. Actually, in my version I just use
Invoke/GetValue etc directly, but you might have different needs...
Marc
Jul 24 '08 #3
On 24 Lip, 12:14, Klaudiusz Bryja <bryja_klaudi.. .@poczta.fmwrot e:
Hi,

I need Delegate.Create Delegate method equivalent in compact
framework.

Best regards,
Klaudiusz
Sorry i send to fast. I have solution like this but it create delegate
EventHandler type only. I try to use reflection to call constructor
(e.g. do something like Deleagte a = new SomeEventHandle r()) but I can
get target method address. Meybe you have something which create
Delegate of any type.
Jul 24 '08 #4
On 24 Lip, 12:35, Marc Gravell <marc.grav...@g mail.comwrote:
It is there in 3.5; in 2.0 you can invoke the method (etc) directly via
Invoke, or if you absolutely *need* a delegate perhaps use an anonymous
method (and capture) to create it, i.e.

(where getter is the instance of a Getter delegate - think Func<,>)

#if CF2
getter = delegate(TEntit y instance) {
return (TValue)propert y.GetValue(inst ance, null);
};
#else
getter = (Getter)Delegat e.CreateDelegat e(
typeof(Getter), null, method);
#endif

A bit hacky, but it should work. Actually, in my version I just use
Invoke/GetValue etc directly, but you might have different needs...

Marc
Hi,

I can't use NetCF 3.5. I can use only 2.0.
Jul 24 '08 #5
Here's a CF2 example with a button and a textbox, linked dynamically on
name (i.e. in the scenario where we can't just use += etc). It isn't as
elegant as we might like, but it works:

public Form1()
{
InitializeCompo nent();

// hook "Click" of button to "SomeMethod "
MethodInfo method = GetType().GetMe thod("SomeMetho d");
EventHandler handler = delegate(object s, EventArgs e)
{
method.Invoke(t his, new object[] { s, e });
};
button1.GetType ().GetEvent("Cl ick")
.AddEventHandle r(button1, handler);
}
public void SomeMethod(obje ct sender, EventArgs args)
{
label1.Text = "it worked";
}
Jul 24 '08 #6
Yes; my example was *for* CF 2.0. In CF 3.5 you just use
Delegate.Create Delegate. See the other exaple I've just posted.

Marc
Jul 24 '08 #7
On 24 Lip, 12:44, Marc Gravell <marc.grav...@g mail.comwrote:
Here's a CF2 example with a button and a textbox, linked dynamically on
name (i.e. in the scenario where we can't just use += etc). It isn't as
elegant as we might like, but it works:

public Form1()
{
InitializeCompo nent();

// hook "Click" of button to "SomeMethod "
MethodInfo method = GetType().GetMe thod("SomeMetho d");
EventHandler handler = delegate(object s, EventArgs e)
{
method.Invoke(t his, new object[] { s, e });
};
button1.GetType ().GetEvent("Cl ick")
.AddEventHandle r(button1, handler);
}
public void SomeMethod(obje ct sender, EventArgs args)
{
label1.Text = "it worked";
}
Hi,

I do like you and it's work. My question was - how to create delegate
having eventhandlertyp e. In you example you know the type of delegate
(EventHandler) but I have this information in GetEvent("name of
event").EvenatH andlerType.

Try you example with KeyDown event. You should get argumentexcepti on
because you create EventHandler but you should create KeyEventHandler .
I want solution which create delegate and I said it has to be
KeyEventHandler type or MouseEventHandl er or something else.
Jul 24 '08 #8
On 24 Lip, 12:35, Marc Gravell <marc.grav...@g mail.comwrote:
It is there in 3.5; in 2.0 you can invoke the method (etc) directly via
Invoke, or if you absolutely *need* a delegate perhaps use an anonymous
method (and capture) to create it, i.e.

(where getter is the instance of a Getter delegate - think Func<,>)

#if CF2
getter = delegate(TEntit y instance) {
return (TValue)propert y.GetValue(inst ance, null);
};
#else
getter = (Getter)Delegat e.CreateDelegat e(
typeof(Getter), null, method);
#endif

A bit hacky, but it should work. Actually, in my version I just use
Invoke/GetValue etc directly, but you might have different needs...

Marc
Hi Marc,
I have question for you. You said that use CF2 but I haven't TEntity
and TValue types. What is it (I search information but I get something
connected to LINQ)? What is "property" object?
Jul 24 '08 #9
I'm sorry, I didn't do a very good job of explaining...

That code was copy/paste from some existing code that uses generics;
TEntity / TValue are the generic types of the class and property-type
(respectively), and "property" is the PropertyInfo - i.e. here:

public class Foo {
public int Bar {set;set;}
}

TEntity is Foo, TValue is int, and property is Bar... basically that
code is from some code that manages data access to an entity (as part of
a serialization/deserialization routine).

Marc
Jul 24 '08 #10

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

Similar topics

4
2168
by: Tim Werth | last post by:
I am trying to use reflection to add an event handler for the RowUpdated event of the OracleDataAdapter object (ODP.NET), but the same thing can be said for SqlDataAdapter if you only use reflection. The code I supplied is based on the SqlDataAdapter with reflection. The error occurs when trying to create the delegate that will be passed in...
0
1823
by: Matt | last post by:
I'm trying to use late binding to automate Excel from C# so as to run with multiple versions of Excel, and am hoping to avoid referencing any Excel PIA in my project. But I need to add a C# event handler to do some processing before Excel closes. Ildasm shows the handler Invoke like this: void(class...
3
3926
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() {
4
2420
by: KC Eric | last post by:
Hi all, I have a dll file, it has a class, say: class Temp, this class has a function which has a delegate as a parameter, say: public void Test(GameOverHandler _overHandler)
5
3612
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 pointer when the first object is not 0, but I can't find its equivalent type in .NET. I would like to save an object of that type and use that object to...
4
2550
by: CJ Taylor | last post by:
What does this mean? This method creates delegates for static methods only. An instance method is a method that is associated with an instance of a class; a static method is a method that is associated with the class itself. So I'm trynig to use System.Delegate.CreateDelegate (Type, MethodInfo) : Delegate and having some issues...
1
2728
by: CJ Taylor | last post by:
Alright, I probably wont be able to get this question answered, but maybe someone has even more experience than me with delegates... Wow... that sounded fecisious. =) So, I'm trying to dynamically create a delegate where the parameters match on the base level (position is the same, and there base types are the same.) i.e.
5
1507
by: needin4mation | last post by:
Learning about delegates (again, I admit), I think I finally get it, maybe. I can reference any method in any class in the same namespace as long as it has the same signature. Right? But how does it know? Does the .NET runtime keep a list of all the possible methods that could be called and then when the delegate is invoked, just look...
22
2400
by: =?Utf-8?B?c2lwcHl1Y29ubg==?= | last post by:
Hi I have an Assembly that has various usercontrols that all implemnet an Interface The Interface public interface ISettings { bool SaveSettings();
0
7412
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7594
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7748
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7697
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5285
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4900
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3395
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
979
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
648
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.