Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Reflection - Changing a method visibility

Posted on 2011-02-17
8
Medium Priority
?
581 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 64

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
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!

 
LVL 8

Accepted Solution

by:
TheMozz earned 2000 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 64

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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

722 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