[Mono-list] GetMethodFromHandle and NotImplementedException

Carlos Ble ble.jurado at gmail.com
Fri Jul 20 08:37:23 EDT 2007


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 <ble.jurado at gmail.com>:
>
> 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 <miguel at novell.com>:
> >
> >
> > > 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.
> >
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-list/attachments/20070720/3bfdcd8f/attachment.html 


More information about the Mono-list mailing list