Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

How to access non static method at run time in WPF(C#)

$
0
0

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?



Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>