Passing object[] Elements as Parameters to Invoke()
-
Hi guys! Maybe anyone can help me with this: I have a object[] with values e.g.:
object[] obj = new object[]{"a",1};
Furthermore I have a dynamic method which is in reality for example a
Func function;
Is there a way to use the values of the object[] as parameters for the function? Or how can I invoke the method with the values from the object[]? ----------------- Why is this needed? I have classes which store Func<1..n> within a dynamic property e.g.
class A
public dynamic Algorithm;
Algorithm = new System.Func((x,y) => { return x + y; });class B
public dynamic Algorithm;
Algorithm = new System.Func((x,y) => { return x / y * z; });. By iterating through MethodInfo[] I get
Type inputType = parameter.ParameterType;
Type returnType = member.ReturnType;and can therefore create my UI. Now I can create objects out of this by using the Activator
object inputParameterObject = Activator.CreateInstance(inputType);
In the UI I fill in the values.
inputParameterObject1 = a;
inputParameterObject2 = 1;The inputParameterObjects are stored in an object[] Now I need to invoke the Func<1..n> by passing the values from the UI.
Algorithm.Invoke(inputParameterObjectArray);
does not work as it is not equal to
Algorithm.Invoke("a",1);
Or in other words
Algorithm.Invoke(object[]) != Algorithm.Invoke(string,int) || Algorithm.Invoke(object,object)
Help would be appreciated! So long,
-
Hi guys! Maybe anyone can help me with this: I have a object[] with values e.g.:
object[] obj = new object[]{"a",1};
Furthermore I have a dynamic method which is in reality for example a
Func function;
Is there a way to use the values of the object[] as parameters for the function? Or how can I invoke the method with the values from the object[]? ----------------- Why is this needed? I have classes which store Func<1..n> within a dynamic property e.g.
class A
public dynamic Algorithm;
Algorithm = new System.Func((x,y) => { return x + y; });class B
public dynamic Algorithm;
Algorithm = new System.Func((x,y) => { return x / y * z; });. By iterating through MethodInfo[] I get
Type inputType = parameter.ParameterType;
Type returnType = member.ReturnType;and can therefore create my UI. Now I can create objects out of this by using the Activator
object inputParameterObject = Activator.CreateInstance(inputType);
In the UI I fill in the values.
inputParameterObject1 = a;
inputParameterObject2 = 1;The inputParameterObjects are stored in an object[] Now I need to invoke the Func<1..n> by passing the values from the UI.
Algorithm.Invoke(inputParameterObjectArray);
does not work as it is not equal to
Algorithm.Invoke("a",1);
Or in other words
Algorithm.Invoke(object[]) != Algorithm.Invoke(string,int) || Algorithm.Invoke(object,object)
Help would be appreciated! So long,
I haven't tried it, but could you use the
.DynamicInvoke
method instead? Its signature looks like what you want. -
I haven't tried it, but could you use the
.DynamicInvoke
method instead? Its signature looks like what you want.