1

As explained in this thread Find a private field with Reflection? reflection can be used to set a private field, and I've done so successfully in MOSS 2007 which is using asp.net 2.0. I'm wondering if my code is going to break in SharePoint 2010, which I guess comes down to whether or not the backing version of asp.net, which is asp.net 3.5, would allow it.

To summarize Does asp.net 3.5 allow private member variables of a superclass to be set using reflection from an inheriting class?

Any comments?

Community
  • 1
  • 1
KyleM
  • 121
  • 1
  • 2
  • 7

1 Answers1

5

Yes it does (*) if there's sufficient trust but that's the least of your worries. There's a reason why that field is private. It's an implementation detail that you shouldn't worry about/mangle with and private is also documenting "we might delete/rename or do what ever we feel like with this field with out worrying if it breaks your code"

Instead of keeping your fingers crossed and hope it won't break this time round believe that some future Update Will and tale appropriate actions. That is rewrite your code to not accessing private members

(*) The CLR is the same for 2.0 and 3.5.

Rune FS
  • 21,497
  • 7
  • 62
  • 96