Getting 'basic' datatype rather than weird nullable one, via reflection in c# -


my basic need datatypes anonymous type generated linq sql query.

i have piece of code (cleverer write, since haven't delved reflection) returns datatypes anonymous types, , works elements marked 'not nullable' in linq2sql properties. so, if have string return system.string. however, when element nullable end 'full name' of being:

{name = "nullable1" fullname = "system.nullable1[[system.decimal, mscorlib, version=4.0.0.0, culture=neutral, publickeytoken=b77a5c561934e089]]"}

all want extract system.decimal type in such case (and in cases of strings or whatever, i'd want system.string). i've looked through properties , can't find seems store this.

    private static dictionary<string, type> getfieldsfortype<t>(ienumerable<t> data)     {         object o = data.first();          var properties = o.gettype().getproperties();          return properties.todictionary(property => property.name, property => property.propertytype);     } 

the linq query (which don't think matters here):

var thedata = r in db.tbltestedits select new { myitem = r.textfield, mydecimal = r.decimalfield };  

i found link seems try address similar thing.
http://ysgitdiary.blogspot.com/2010/02/blog-post.html

though seems return "string" of type rather actual type, need. not sure how convert such thing.

many all.

private static type getcoretype(type type) {     if (type.isgenerictype &&         type.getgenerictypedefinition() == typeof(nullable<>))         return nullable.getunderlyingtype(type);     else         return type; } 

Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -