views:

238

answers:

1

How do i check if a Type is a struct? IsClass worked perfectly then my reflection stop behaving as i expected when i change the class to the struct. How do i check if its a struct? -edit- i need to check for class/structs. Nothing else, i cant match longs, ints, etc by accident. DateTime may be ok i am using this to search a Attribute/FieldType inside of the type i am checking

+6  A: 

Type.IsValueType should do the trick.

Matt Greer
Now long and ints are confused with structs.
acidzombie24
@acidzombie24: `long` and `int` **are** structs. What confusion? Maybe you mean `IsPrimitive`?
Marc Gravell
I can write IsPrimitive == false (as a shortcut and i have an alternative to most primitives) and use IsValueType. Thanks :)
acidzombie24
acidzombie24: note this will depend on what you want to exclude. For example, `decimal` is **NOT** a primitive, even though it looks that way in C#. Hopefully this won't be an issue for your use case...
itowlson
itowlson: Test are all in place and decimal isnt an issue. There are select types i support and user structs are one but only if it has certain attributes :)
acidzombie24