Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Object with user-configurable property "visibility"

Tags:

c#

properties

oop

I have a User object with a bunch of properties. I have a requirement that states when a user sets up their information, they need the ability to state which properties of their profile are visible to others.

The way I had envisioned this was adding an additional property - a list of string that would contain the property names that were publicly visible. I could then implement a method called ToPublicView() or something similar that would use reflection to set non-public properties to null or default.

Is this a reasonable approach, or is there a better way?

like image 987
Cork Avatar asked Nov 03 '22 23:11

Cork


1 Answers

I think it's the simplest of the options. If reflection start to kill your performance, you may want to have a dictionary of property-delegate for accessing the values.

And as the requirement is not to have dynamic properties but just to mark the existing ones, it doesn't make sense to have all the properties in a dynamic way (like a list of property objects). Also, having them as actual properties will make the code more readable when you have to use it for the rest of the application.

like image 155
Ivo Avatar answered Nov 12 '22 17:11

Ivo