Hi,
I need Delegate.CreateDelegate method equivalent in compact
framework.
Best regards,
Klaudiusz 9 3015
On 24 Lip, 12:14, Klaudiusz Bryja <bryja_klaudi...@poczta.fmwrote:
Hi,
I need Delegate.CreateDelegate 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).
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(TEntity instance) {
return (TValue)property.GetValue(instance, null);
};
#else
getter = (Getter)Delegate.CreateDelegate(
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
On 24 Lip, 12:14, Klaudiusz Bryja <bryja_klaudi...@poczta.fmwrote:
Hi,
I need Delegate.CreateDelegate 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 SomeEventHandler()) but I can
get target method address. Meybe you have something which create
Delegate of any type.
On 24 Lip, 12:35, Marc Gravell <marc.grav...@gmail.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(TEntity instance) {
return (TValue)property.GetValue(instance, null);
};
#else
getter = (Getter)Delegate.CreateDelegate(
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.
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()
{
InitializeComponent();
// hook "Click" of button to "SomeMethod"
MethodInfo method = GetType().GetMethod("SomeMethod");
EventHandler handler = delegate(object s, EventArgs e)
{
method.Invoke(this, new object[] { s, e });
};
button1.GetType().GetEvent("Click")
.AddEventHandler(button1, handler);
}
public void SomeMethod(object sender, EventArgs args)
{
label1.Text = "it worked";
}
Yes; my example was *for* CF 2.0. In CF 3.5 you just use
Delegate.CreateDelegate. See the other exaple I've just posted.
Marc
On 24 Lip, 12:44, Marc Gravell <marc.grav...@gmail.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()
{
InitializeComponent();
// hook "Click" of button to "SomeMethod"
MethodInfo method = GetType().GetMethod("SomeMethod");
EventHandler handler = delegate(object s, EventArgs e)
{
method.Invoke(this, new object[] { s, e });
};
button1.GetType().GetEvent("Click")
.AddEventHandler(button1, handler);
}
public void SomeMethod(object sender, EventArgs args)
{
label1.Text = "it worked";
}
Hi,
I do like you and it's work. My question was - how to create delegate
having eventhandlertype. In you example you know the type of delegate
(EventHandler) but I have this information in GetEvent("name of
event").EvenatHandlerType.
Try you example with KeyDown event. You should get argumentexception
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 MouseEventHandler or something else.
On 24 Lip, 12:35, Marc Gravell <marc.grav...@gmail.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(TEntity instance) {
return (TValue)property.GetValue(instance, null);
};
#else
getter = (Getter)Delegate.CreateDelegate(
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?
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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()
{
|
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)
|
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...
|
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...
|
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...
|
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...
|
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();
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
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,...
|
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$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
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...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
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...
|
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...
| |