Hello, I want to call inherited method at run time. When method is static, it's works fine. But I want to inherit method from interface,so I cant make method as static. code sample as below.
public interface INameList<T> { IList<T> GetRecords(); } public class NameService : INameList< NameService > { public IList<NameService > GetRecords() { return null; } } public class DataPager { public void GetItemSource<T>() { MethodInfo info = typeof(T).GetMethod("GetRecords"); object items = info .Invoke(this, null); ItemsSource = (IEnumerable)items; } }
I call method from as follows
GetItemSource< NameService>();
Here returns run time exception since GetRecords() method is non static. How can I solve this?