How to prevent Type.GetProperties() from accessing properties in object

Go To StackoverFlow.com

1

I use massive.cs as a DAL, but I create Models that have Lists for their Children.

The problem is I can't figure out a good way to hide those from GetProperties(). Massive uses that to create the expando object, and without doing heavy editing, I can't think of a good way to hide those properies. Is there an attribute or anything like that?

2012-04-05 16:57
by Jeremy Boyd
the important part is which parts still need the access to it. i.e. does your other code still make use of those properties, is it internal to a lib etc - NSGaga 2012-04-05 17:54
The properties need to be public, but also not visible to GetProperties(). internal almost works but I still need access to the properties in the ASPX pages - Jeremy Boyd 2012-04-05 17:56


4

Massive uses the overload of GetProperties() that takes no parameters (massive.cs:76). As per the documentation, that method "Returns all the public properties of the current Type."

Further, "A property is considered public to reflection if it has at least one accessor that is public." So just make sure the getters and setters are private, or are explicit interface implementations.

2012-04-05 17:10
by Chris Shain
Problem is if I make it internal (which allows me access in the rest of my application), I lose the ability to use it in the ASPX pages, but it isn't Getted from the GetProperties... which is what I'm doing now - Jeremy Boyd 2012-04-05 17:53
Then make it an explicit interface implementation as I suggested. Explicit interface getters and setters shouldn't be exposed via the method that Massive is using - Chris Shain 2012-04-05 17:55
The reason is because even though they are public through the interface, the Default binding flag only gets declared properties - Jeremy Boyd 2012-04-05 18:05
Right- they are exposed by the class, but not via the Type that you are specifying. They are only exposed via the interface - Chris Shain 2012-04-05 18:13


2

It sounds like you are trying to hide some code? If so, you have to change your modifier to internal or private from what I assume is public. Otherwise, you could add a key to make it so that your code cannot be used by others through obfuscation...however, there is no perfect way to hide your code as far as I know...

2012-04-05 17:04
by Justin Pihony
Ads