Deriving a sealed class

S

shawnz

Is there any way to either derive a sealed class, or access private
members of a sealed class? Either that, or is there a way to run
internal methods in a sealed class outside the current assembly? I
don't mind if the solution is hackish, the dll i'm writing is already
full of code hacks. =p
 
J

Jon Skeet [C# MVP]

shawnz said:
Is there any way to either derive a sealed class, or access private
members of a sealed class? Either that, or is there a way to run
internal methods in a sealed class outside the current assembly? I
don't mind if the solution is hackish, the dll i'm writing is already
full of code hacks. =p

You can't derive from a sealed class, but you can access members you're
not supposed to using reflection *if* you've got sufficient
permissions.
 
S

shawnz

Thanks for the advice! I didn't think to use reflection on them... This
will work on types outside the current assembly (in a reference) right?
Also, could you give me a function to point me in the right direction
doc-wise?
 
J

justncase80

Probably the best thing to do instead is to take a hard look at your
design and refactor it until you get rid of the hacks. If your code is
already "full of hacks" you're just digging your grave deeper.

~justin
 
S

shawnz

To be honest, the reason behind this is i'm trying to get around the
Internet wlm add-in sandbox without patching MessengerClient.dll. So,
using dodgy code hacks is almost my only line of defense before I
resort to doing something that can't be distributed. :p
 
I

Ian Semmel

You could put an instance of the class in your class and expose all the
properties and then either call the sealed class or do your own stuff.
 
M

Mike Schilling

shawnz said:
Thanks for the advice! I didn't think to use reflection on them... This
will work on types outside the current assembly (in a reference) right?
Yes.

Also, could you give me a function to point me in the right direction
doc-wise?

Look at System.Reflection.FieldInfo and System.Reflection.MethodInfo.
 
S

shawnz

shawnz said:
Thanks for the advice! I didn't think to use reflection on them... This
will work on types outside the current assembly (in a reference) right?
Also, could you give me a function to point me in the right direction
doc-wise?

Also, another quick question, I realized I can't set the variables
myself because their types depend on to many other internal things. Is
there a way to just call the internal "Startup()" function from my dll?
Could I possibly inject a function into my instance of the class and
run that to run "Startup()"?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top