Hi everybody.
I'm invoking public factory methods using Csla Reflection, and came across a particular case where
public static object CallFactoryMethod(Type objectType, string method, params object[] parameters)
{
object returnValue;
MethodInfo factory = objectType.GetMethod(method, factoryFlags, null, MethodCaller.GetParameterTypes(parameters), null);
if (factory == null)
....
presents an issue when it calls [MethodCaller.GetParameterTypes(parameters)] and [parameters] is null.
When [GetParameterTypes(null) is executed, it adds [result.Add(typeof(object));] to the result [type] list.
public static Type[] GetParameterTypes(object[] parameters)
{
List<Type> result = new List<Type>();
if (parameters == null)
{
result.Add(typeof(object));
}
else
I have a particular case where I define 2 public static methods on a class like this:
1. public static NewObject() {...}
2. public static NewObject(object obj} {...}
By default, when I try to Invoke the 1st. method with no parameters, CallFactoryMethod(..) with [null] as params[], it defaults to the 2nd. version of the method, due to its default parameter added by GetParameterTypes(..).
And it throws an exception because I'm not sending the [object] parameter, instead, I'm sending null as params.
I didn't get to check the implications of changing this behaviour on CSLA.
If anyone can suggest a simple workaround, it's welcome.
For now I'll use my own Reflection Functions to call on this factory methods for NewObject on my BOs.
Thanks to all,
Troncho