Solved

Reflection - Changing a method visibility

Posted on 2011-02-17
8
575 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
  • 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

861 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