I have the following two functions:
public class MyClass { public void Save<TObject>(TObject object) where TObject : class { } public void Save<TObject>(TObject object, String strValue) where TObject : class { } }
I want to be able to dynamically call the first save function, similar to the following:
public void DoSomething<T>(String strMethod) where T : class { T myObject = Activator.CreateInstance<T>(); MyClass.GetType().GetMethod(strMethod, new Type[] { typeof(T) }).MakeGenericMethod(typeof(T)).Invoke(null, new[] { myObject }); }
Unfortunately, when I do this, it cannot match the first save function. If I remove new Type[] { typeof(T) } , I am stuck with the ambiguity problem. What am I missing?
source share