Exclude property from getType().GetProperties()

后端 未结 6 1545
故里飘歌
故里飘歌 2020-12-24 07:06

Hi i\'m working in a class library using C#, and i have some classes with some properties.

I just wanna know if i can add something to exclude some properties form t

6条回答
  •  没有蜡笔的小新
    2020-12-24 07:21

    Although I prefer, and am going to use, the attribute way, I did get this working in a different way that might help the OP.

    Here's an example:

    PropertyInfo[] properties = record.GetType().GetProperties().Where(p => !"Description".Equals(p.Name)).ToArray();
    

    This will exclude any properties that are named "Description". If you're not able to change the class that contains the properties this could be an option. Again, I prefer the attribute way mentioned above.

提交回复
热议问题