I would like to know if a type that i pass is a system type or a type that I created. How can i know this? Look:
// Obs: currentEntity can be any entity that i created
var currentProperties = currentEntity.GetType().GetProperties();
foreach (var property in currentProperties)
{
if (/* Verify here if the property is a system type */)
{
// Do what i want...
}
}
What is the best way to verify that?
OBS: Counts as a “system type” all types of the core standard library, in an assembly signed by Microsoft like: DateTime, String, Int32, Boolean (all types in mscorlib.dll | System.dll)…
OBS2: My entities will not inherit from those “system types”.
OBS3: My entity could be any type that I created, so I cannot specify in the comparison.
OBS4: I need to do the comparison without the specifying if the the is equal to String, Boolean…
What counts as a “system” type? You could check whether:
Systemor starts withSystem.Once you’ve defined what you mean by “system”, that pretty much suggests the code used to check it. For example:
if (type.Assembly == typeof(string).Assembly)var publisher = typeof(string).Assembly.Evidence.GetHostEvidence<Publisher>();– followed by a check forpublisherhaving the right certificate for Microsoftif (SystemTypes.Contains(type))– once you’ve come up with your own list of system typesif (SystemAssemblies.Contains(type.Assembly))– once you’ve come up with your own list of system assemblies (more practical)EDIT: As per comments, if you’re happy with just
mscorlibandSystem.dll: