Link to home
Start Free TrialLog in
Avatar of Unimatrix_001
Unimatrix_001Flag for United Kingdom of Great Britain and Northern Ireland

asked on

Reflection - Changing a method visibility

Hi,

I've got a MethodInfo object and I'm wanting to change that method (using reflection) from public to private. Possible?

Thanks,
Uni
Avatar of TheMozz
TheMozz
Flag of United States of America image

Are you writing an assembly at run time, or what? What would the purpose/reason be? Just trying to understand the why before giving best answer on how.
Avatar of Unimatrix_001

ASKER

Hello!

Well, I'm playing around with some ideas for copy protection, also I wouldn't mind learning a little more about reflection as all the vast majority of stuff seems to be just pulling data and calling an existing method... nothing too exciting if you ask me.

Thanks,
Uni
Avatar of Fernando Soto
Hi Unimatrix_001;

If you take a look at the MethodInfo class you will see that all its propertiesare Get's and non are Set's properties. So there is no way that I know to do this, sorry.

MethodInfo Class
http://msdn.microsoft.com/en-us/library/system.reflection.methodinfo.aspx

Fernando
ASKER CERTIFIED SOLUTION
Avatar of TheMozz
TheMozz
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Oh boy... Things just got difficult...
The Reflection.Emit permits you create at run time code it does not permit you to change the scope of a existing method from private to public.
LOL! We looked into that for the same reasons a while back, but ran out of time :( It has a lot of potention for use when installing programs, you could emit certain assemblies for things. But like you said, it gets difficult fast! Thanks!
The Reflection.Emit permits you create at run time code it does not permit you to change the scope of a existing method from private to public.
It does seem though as code could be copied and edited before being ran in a new assembly...