Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 589
  • Last Modified:

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
0
Unimatrix_001
Asked:
Unimatrix_001
  • 3
  • 3
  • 2
1 Solution
 
TheMozzCommented:
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
 
Unimatrix_001Author Commented:
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
 
Fernando SotoRetiredCommented:
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
TheMozzCommented:
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
 
Unimatrix_001Author Commented:
Oh boy... Things just got difficult...
0
 
Fernando SotoRetiredCommented:
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
 
TheMozzCommented:
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
 
Unimatrix_001Author Commented:
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!

  • 3
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now