Created
August 13, 2010 21:37
-
-
Save jurrchen/523582 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Reflection; | |
namespace clojure.lang | |
{ | |
public class GenGenericMethod | |
{ | |
public static object CreateStatic(Type parentclass, string method, PersistentVector gentypes, PersistentVector argv) | |
{ | |
Type[] cleantypes = new Type[gentypes.Count]; | |
gentypes.CopyTo(cleantypes, 0); | |
if (argv.Count > 0) | |
{ | |
Type[] argtypes = new Type[argv.Count]; | |
for (int i = 0; i < argv.Count; i++) | |
{ | |
argtypes[i] = argv.valAt(i).GetType(); | |
} | |
object[] cleanargv = new object[argv.Count]; | |
argv.CopyTo(cleanargv, 0); | |
return parentclass.GetMethod(method, argtypes) | |
.MakeGenericMethod(cleantypes) | |
.Invoke(null, cleanargv); | |
} | |
else | |
{ | |
return parentclass.GetMethod(method, new Type[0]) | |
.MakeGenericMethod(cleantypes) | |
.Invoke(null, new object[0]); | |
} | |
} | |
public static object Create(object obj, string method, PersistentVector gentypes, PersistentVector argv) | |
{ | |
Type parentclass = obj.GetType(); | |
Type[] cleantypes = new Type[gentypes.Count]; | |
gentypes.CopyTo(cleantypes, 0); | |
if (argv.Count > 0) | |
{ | |
Type[] argtypes = new Type[argv.Count]; | |
for(int i=0; i<argv.Count; i++) | |
{ | |
argtypes[i] = argv.valAt(i).GetType(); | |
} | |
object[] cleanargv = new object[argv.Count]; | |
argv.CopyTo(cleanargv, 0); | |
return parentclass.GetMethod(method,argtypes) | |
.MakeGenericMethod(cleantypes) | |
.Invoke(obj, cleanargv); | |
} | |
else | |
{ | |
return parentclass.GetMethod(method,new Type[0]) | |
.MakeGenericMethod(cleantypes) | |
.Invoke(obj, new object[0]); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment