Gibt es eine Funktion zum Überprüfen, ob ein Objekt ein integrierter Datentyp ist?
Ich würde gerne sehen, ob es sich bei einem Objekt um ein Objekt handelteingebauter Datentyp in c #
Ich möchte nicht gegen alle von ihnen prüfen, wenn möglich.
Ichnicht will das machen:
Object foo = 3;
Type type_of_foo = foo.GetType();
if (type_of_foo == typeof(string))
{
...
}
else if (type_of_foo == typeof(int))
{
...
}
...
Aktualisieren
Ich versuche rekursiv eine PropertyDescriptorCollection zu erstellen, bei der die PropertyDescriptor-Typen möglicherweise keine eingebauten Werte sind. Also wollte ich so etwas machen (Anmerkung: das funktioniert noch nicht, aber ich arbeite daran):
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;
}
// This was the orginal posted answer to my above question
private bool IsBulitin(Type inType)
{
return inType.IsPrimitive || inType == typeof(string) || inType == typeof(object);
}