المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Passing object[] Elements as Parameters to Invoke()



C# Programming
10-03-2012, 10:13 PM
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<span class="code-keyword"string/span,span class="code-keyword"int/span,int> 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 within a dynamic property
e.g.
class A public dynamic Algorithm; Algorithm = new System.Func<span class="code-keyword"int/span,span class="code-keyword"int/span,int>((x,y) => { return x + y; }); class B public dynamic Algorithm; Algorithm = new System.Func<span class="code-keyword"double/span,span class="code-keyword"double/span,span class="code-keyword"int/span,double>((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 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,