Identify property/object type

  • Thread starter Thread starter Vikram
  • Start date Start date
V

Vikram

Hi,
Using refelction how to identify property of a object is of type:
1. Native i.e. string, int, boolean etc.
2. User defined calss
3. List/collection type

Thanks
 
Vikram said:
Using refelction how to identify property of a object is of type:
1. Native i.e. string, int, boolean etc.
2. User defined calss
3. List/collection type

PropertyInfo.PropertyType.
 
Vikram said:
What to check in PropertyInfo. Propertytype fro below mentioned 3 types?

Well, you'll need to be precise about what exactly you mean by
"native", and "collection type". For instance, what about a user-
defined collection, or a type derived from List<T>?

Type.IsPrimitive *may* be all you want for "native" but you'll need to
work out exactly what you mean before you can tell.
 
Native I mean .Net primitive like string , int, boolean etc. value of which
can be compared directly using '=' operator.
If a List or collection, in that case again I need to loop thorugh each
object of list and idnetify whether it is a primitive type or an object.
Hence, I want to comare value of each property of two objects, in a generic
way.
 
Vikram said:
Native I mean .Net primitive like string , int, boolean etc. value of which
can be compared directly using '=' operator.

It's the "etc" which is the problem. Would you include Guid in there?
What about Decimal?
If a List or collection, in that case again I need to loop thorugh each
object of list and idnetify whether it is a primitive type or an object.
Hence, I want to comare value of each property of two objects, in a generic
way.

So next you need to work out *exactly* what counts as "list or
collection". Anything implementing IList? What about IEnumerable<T>?
 
Back
Top