Solved

Reflection - Changing a method visibility

Posted on 2011-02-17
8
572 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 62

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
 
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 3

Author Closing Comment

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

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

759 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now