linq2sql : get generic type of table

Posted by benpage on Stack Overflow See other posts from Stack Overflow or by benpage
Published on 2010-03-31T00:12:59Z Indexed on 2010/03/31 0:23 UTC
Read the original article Hit count: 650

Filed under:
|
|
|

i think this is a simple question but I've searched around and can't seem to find an answer easily.

if you have

var list = List<int>();
... fill list ...

and you want to get the generic type in list, i realise you could just type:

var t = list.FirstOrDefault().GetType();

Is there another way to do this via just the list, rather than referring to the enumeration?

Reason is, i have a System.Data.Linq.Table<TABLE1> and what i want to do is get the type of TABLE1 from it.

so:

var table = new DataContext().TABLE1s; // this is Table<TABLE1>
var tableType = table.GetType().SomeMethod(); 
// i want tableType to equal TABLE1.GetType()

© Stack Overflow or respective owner

Related posts about generic

Related posts about linq-to-sql