Exclude property from getType().GetProperties()

后端 未结 6 1534
故里飘歌
故里飘歌 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:07

    With the PropertyInfo object you can examine the GetCustomAttributes of the property. So you could add attributes to your properties when you declare them, and then when you are reflecting against the properties, you can choose only the properties that are marked with the attributes you desire.

    Of course if you are actually wanting to somehow prevent someone from reflectively getting your properties, this is not the solution you want.

    Edit: I'm sorry you want GetCustomAttributes, fixed. See this: http://msdn.microsoft.com/en-us/library/kff8s254.aspx

提交回复
热议问题