I am working with a reflection based object translator.
it basically loops through properties of an object, and assigns the values to properties with the same name/
I'm assuming you want to determine if the target type is not a primative. You can probably use TypeCode
for that, for instance:
public bool IsNotCoreType(Type type)
{
return (type != typeof(object) && Type.GetTypeCode(type) == TypeCode.Object);
}
Any non-primitive should return TypeCode.Object
as the result of Type.GetTypeCode
, so we can check that we get that and that the type itself is not System.Object
.
Perhaps that would help?
UPDATE: I've renamed the method to IsNotCoreType to cover both primitives and non-primitives such as String
, DateTime
, etc. (see comments below).
string is an exception, the only primitive type in .NET which is a reference type. You have to consider this exception in your code so that you check if IsClass
is true and type is not the same as System.String
.