How to write a simple method that checks whether a particular type is a custom structure (created using public struct { }; ) or not.
Checking Type.IsValueType not enough, as this is also true for int , long , etc. and adding a check on !IsPrimitiveType does not exclude decimal , DateTime and possibly some other value types. I know that most of the built-in value types are actually "structures", but I only want to check for "custom structures"
These questions are basically the same, but without an answer I need:
EDIT: of the answers mentioned, βchecking for aβ system prefix βwas the most stable (although it still breaks). Finally, I decided to create an Attribute that you need to decorate with a structure so that the structure picks it up as a custom structure. (Another choice that I I thought it was creating an empty interface, and let the structure implement this empty interface, but the attribute path seemed more elegant)
Here is my original user structure controller, if anyone is interested:
type.IsValueType && !type.IsPrimitive && !type.Namespace.StartsWith("System") && !type.IsEnum
SztupY
source share