[Solved] how to achieve pass TType value by the MyEvents function [closed]


You are diving into world of generics. Using a generic type parameter T you can write a single class that other client code can use without incurring the cost or risk of runtime casts or boxing operations.

A generic class, such as MListBox<T> cannot be used as-is because it is not really a type. so to use MListBox<T>, you must declare and instantiate a constructed type by specifying a type argument inside the angle brackets.

eg

MListBox<YourClass> a = new MListBox<YourClass>();

where YourClass is type parameter you intend to pass in

more info on generics

http://msdn.microsoft.com/en-us/library/512aeb7t.aspx

Update

    public class MListBox<T, M> : ListBox
        where T : class
        where M : class, new()
    {
        public void LoadList()
        {
            MyEvents<T, M>.LoadList("getList").ForEach(w => this.Items.Add(w));
        }
    }

    public void main(string[] args)
    {
        MListBox<object,STOCK> mb = new MListBox<object,STOCK>();
        mb.LoadList();
    }


    public static class MyEvents<T, M>
        where T : class
        where M : class, new()
    {
        public static M m;
        public static T t;
        public static List<T> LoadList(string _method)
        {
            m = new M();
            MethodInfo method = typeof(M).GetMethod(_method);
            List<T> ret = (List<T>)method.Invoke(m, null);
            return ret;
        }
    }

wrapper class to be used in xaml

class StockListBox : MListBox<object,STOCK>
{
}

use in xaml as, where local is your namesapce

<local:StockListBox />

9

solved how to achieve pass TType value by the MyEvents function [closed]