Ignore collection properties in PropertyInfo

Posted by LukePet on Stack Overflow See other posts from Stack Overflow or by LukePet
Published on 2010-05-14T14:02:21Z Indexed on 2010/05/14 14:04 UTC
Read the original article Hit count: 212

Filed under:
|
|

I have a function with this code:

foreach (PropertyInfo propertyInfo in typeof(T).GetProperties()){
//SOME CODE
if (propertyInfo.CanWrite)
    propertyInfo.SetValue(myCopy, propertyInfo.GetValue(obj, null), null);
}

I would avoid to check "collection" properties; to do this now I have insert this control:

 if (propertyInfo.PropertyType.Name.Contains("List")
     || propertyInfo.PropertyType.Name.Contains("Enumerable")
     || propertyInfo.PropertyType.Name.Contains("Collection"))
     continue;

but, It don't like me!

Which is a better way to do it?

© Stack Overflow or respective owner

Related posts about c#

Related posts about property