Sorry there was an error in the code before.
This is the right Main method (working on .Net):


public static void Main(string[] args)

{

Console.WriteLine("Hello World!");

TestClass<int> test = new TestClass<int>();

RuntimeMethodHandle methodHandle = test.GetType().GetProperty("MyList"
).GetGetMethod().MethodHandle;

MethodBase methodBase = MethodInfo.GetMethodFromHandle(methodHandle, typeof(
TestClass<int>).TypeHandle);

List<int> list = (List<int>)methodBase.Invoke(test, null);

Console.WriteLine(list.Count);

}
Cheers



2007/7/20, Carlos Ble <[EMAIL PROTECTED]>:

Hi, the sample bellow throwns the NotImplementedException:

using System;
using System.Reflection;
using System.Collections.Generic;

namespace test1
{
    public class TestClass<T>
    {
        private List<T> _myList = new List<T>();

        public List<T> MyList
        {
            get
            {
                return _myList;
            }

        }
    }

    class MainClass
    {
        public static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            TestClass<int> test = new TestClass<int>();
            RuntimeMethodHandle methodHandle =  test.GetType
().GetProperty("MyList").GetGetMethod().MethodHandle;
            RuntimeTypeHandle typeHandle = typeof(int).TypeHandle;
            MethodBase methodBase = MethodInfo.GetMethodFromHandle(methodHandle,
typeHandle);
            List<int> list = (List<int>)methodBase.Invoke(test, null);
            Console.WriteLine(list.Count);
        }
    }
}


2007/7/19, Miguel de Icaza <[EMAIL PROTECTED]>:
>
>
> > I'm getting a NotImplementedException when trying to us
> > GetMethodFromHandle for generics:
> >        * System.Reflection.MethodBase.GetMethodFromHandle
> > (RuntimeMethodHandle handle, RuntimeTypeHandle declaringType)
> > However if I use the non-generic version of the method it works with
> > generic types :-)
> > Will it be implemented soon ?
>
> Please post samples.
>


_______________________________________________
Mono-list maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-list

Reply via email to