开发者

how can i evaluate generic type in runtime in c#

i need to evaluate generic type at runtime using Type.GetType()

Type t  = Type.GetType("className")开发者_C百科;
Table<t> table = dataContext.GetTable<t>();

any ideas please ??


Well, normally you need to get the generic method (e.g. with Type.GetMethod), then call MethodInfo.MakeGenericMethod, then invoke it.

However, is there any reason you don't just want to call DataContext.GetTable(Type)?

You won't be able to use the table generically anyway... so is ITable (the return type of GetTable(type)) good enough for you?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜