Solved

Reflection - Changing a method visibility

Posted on 2011-02-17
8
577 Views
Last Modified: 2012-05-11
Hi,

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

Thanks,
Uni
0
Comment
Question by:Unimatrix_001
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
8 Comments
 
LVL 8

Expert Comment

by:TheMozz
ID: 34917176
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.
0
 
LVL 3

Author Comment

by:Unimatrix_001
ID: 34917222
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
0
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 34917270
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
0
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
LVL 8

Accepted Solution

by:
TheMozz earned 500 total points
ID: 34917314
Ok.
The namespace to start with is System.Reflection.Emit, here are a few links to peek at:

http://www.c-sharpcorner.com/UploadFile/puranindia/419/
http://www.codeproject.com/KB/cs/introreflection.aspx

There are many other topics with it, so there is plenty of reading! Let me know if those aren't what you are looking for.
0
 
LVL 3

Author Closing Comment

by:Unimatrix_001
ID: 34917356
Oh boy... Things just got difficult...
0
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 34917379
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.
0
 
LVL 8

Expert Comment

by:TheMozz
ID: 34917381
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!
0
 
LVL 3

Author Comment

by:Unimatrix_001
ID: 34917404
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...
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question