Class MyClass contains a number of FindAll() methods in parent classes:
class MyClass: ActiveRecordBase<MyClass> {... }
public abstract class ActiveRecordBase<T> : ActiveRecordBase {
protected ActiveRecordBase();
public static T[] FindAll();
public static T[] FindAll(params ICriterion[] criteria);
public static T[] FindAll(DetachedCriteria criteria, params Order[] orders);
public static T[] FindAll(Order order, params ICriterion[] criteria);
public static T[] FindAll(Order[] orders, params ICriterion[] criteria);
...
}
public abstract class ActiveRecordBase : ActiveRecordHooksBase {
protected ActiveRecordBase();
protected internal static Array FindAll(Type targetType);
protected internal static Array FindAll(Type targetType, params ICriterion[]
criteria);
protected internal static Array FindAll(Type targetType, DetachedCriteria
detachedCriteria, params Order[] orders);
protected internal static Array FindAll(Type targetType, Order[] orders,
params ICriterion[] criteria);
...
I need to invoke MyClass parameterless FindAll() method using Reflection.
I tried the following code but GetMethod() returns Ambiquous match found
exception.
How to run parameterless FindAll() method ?
How to add required method signature to GetMethod() parameters or other
solution ?
Type t = Type.GetType("MyClass, MyDll");
// this line causes Ambiquous match found exception :
MethodInfo mi = t.GetMethod("FindAll",
BindingFlags.Public |
BindingFlags.FlattenHierarchy |
BindingFlags.Static);
IList<object> list = (IList<object>)mi.Invoke(null, null);
Andrus
Jon Skeet [C# MVP] - 02 Sep 2007 19:49 GMT
> I need to invoke MyClass parameterless FindAll() method using Reflection.
> I tried the following code but GetMethod() returns Ambiquous match found
[quoted text clipped - 10 lines]
> BindingFlags.FlattenHierarchy |
> BindingFlags.Static);
Use the overload of GetMethod which specifies the types of the
parameters:
MethodInfo mi = t.GetMethod("FindAll", // Name
BindingFlags.Public | // Flags
BindingFlags.FlattenHierarchy |
BindingFlags.Static,
null, // Binder (default)
new Type[0], // Parameter types (none)
null); // Parameter modifiers (ignored)

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Andrus - 02 Sep 2007 23:27 GMT
> Use the overload of GetMethod which specifies the types of the
> parameters:
[quoted text clipped - 6 lines]
> new Type[0], // Parameter types (none)
> null); // Parameter modifiers (ignored)
Jon,
thank you.
Is'nt it better to use Type.EmptyTypes instead of new Type[0] ?
Andrus.
Jon Skeet [C# MVP] - 03 Sep 2007 17:58 GMT
> thank you.
>
> Is'nt it better to use Type.EmptyTypes instead of new Type[0] ?
Well, I find new Type[0] easier to understand personally - but it's
entirely your decision :)

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too