c# - Is there a function to check if an object is a builtin data type? -


i see if object builtin data type in c#

i don't want check against of them if possible.
is, don't want this:

        object foo = 3;         type type_of_foo = foo.gettype();         if (type_of_foo == typeof(string))         {             ...         }         else if (type_of_foo == typeof(int))         {             ...         }         ... 

update

i'm trying recursively create propertydescriptorcollection propertydescriptor types might not builtin values. wanted (note: doesn't work yet, i'm working on it):

    public override propertydescriptorcollection getproperties(attribute[] attributes)     {         propertydescriptorcollection cols = base.getproperties(attributes);          list<propertydescriptor> list_of_properties_desc = createpdlist(cols);         return new propertydescriptorcollection(list_of_properties_desc.toarray());     }      private list<propertydescriptor> createpdlist(propertydescriptorcollection dpcollection)     {         list<propertydescriptor> list_of_properties_desc = new list<propertydescriptor>();         foreach (propertydescriptor pd in dpcollection)         {             if (isbulitin(pd.propertytype))             {                 list_of_properties_desc.add(pd);             }             else             {                 list_of_properties_desc.addrange(createpdlist(pd.getchildproperties()));             }         }         return list_of_properties_desc;     }      // orginal posted answer above question     private bool isbulitin(type intype)     {         return intype.isprimitive || intype == typeof(string) || intype == typeof(object);     } 

well, 1 easy way explicitly list them in set, e.g.

static readonly hashset<type> builtintypes = new hashset<type>     (typeof(object), typeof(string), typeof(int) ... };  ...   if (builtintypes.contains(typeoffoo)) {     ... } 

i have ask why it's important though - can understand how might make difference if it's .net primitive type, explain why want application behave differently if it's 1 of ones c# itself? development tool?

depending on answer question, might want consider situation dynamic in c# 4 - isn't type @ execution time such, system.object + attribute when applied method parameter etc.


Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -