개체가 C에서 builtin data type인지 확인하고 싶습니다.개체가 기본 제공 데이터 형식인지 확인하는 기능이 있습니까?
가능한 경우 모든 개체를 확인하고 싶지 않습니다. 이다
, 내가하지이 작업을 수행 할 할 : 나는 반복적으로의 PropertyDescriptor 유형 값을 내장 될 수있는 PropertyDescriptorCollection을 만들려고 해요
Object foo = 3;
Type type_of_foo = foo.GetType();
if (type_of_foo == typeof(string))
{
...
}
else if (type_of_foo == typeof(int))
{
...
}
...
업데이트. 그래서 내가 이런 걸하고 싶어 (참고 :이 아직 작동하지 않습니다,하지만 난 그게 중이 야) :
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);
}
재귀 적으로 PropertyDescriptorCollection을 만들고 싶습니다. 유형이 내장되어 있는지 확인해야했습니다. 속성 중 하나가 기본 유형이 아닌 경우 새 컬렉션을 만들고 싶습니다. 아픈 질문에 무엇을하려하는지, 아마도 도움이 될지 모르겠다. – SwDevMan81
하지만 그 결정은 C# 사양을 기반으로했을까요?Decimal을 한 가지 방법으로 처리하고 싶지만, DateTime 또는 Guid를 다른 방식으로 처리해야하는 이유는 무엇입니까? –
맞아, 그렇게해서는 안된다. 그건 내 부분에 대한 감시였다. System.ValueType도 확인해야합니다. – SwDevMan81