473,385 Members | 1,780 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

C# reflection help please...

Hi guys,
I am using reflection to get methods in a .dll file but i want to get only user defined methods in the file. Here is what i do;

Expand|Select|Wrap|Line Numbers
  1. Assembly assembly = Assembly.LoadFile(assemblyName);
  2. Type[] types = assembly.GetTypes();
  3. MethodInfo[] methods = null;
  4. foreach(Type t in types)
  5. {
  6.      if(t.Name == "MyClass")
  7.      {    
  8.             methods = type.GetMethods();
  9.      }
  10. }
  11.  
This code gets all methods in the assembly. Is there a way to get only user defined methods?

Thanks in advance
Feb 12 '09 #1
2 1245
PRR
750 Expert 512MB
try this
Expand|Select|Wrap|Line Numbers
  1. Assembly assembly = Assembly.LoadFrom(path);
  2.                 Type[] types = assembly.GetTypes();
  3.                 MethodInfo[] methods = null;
  4.                 List<MethodInfo> classA=new List<MethodInfo>() ;
  5.                 Type tt=null;
  6. foreach (Type t in types)
  7.                 {
  8.                     if (t.Name == "ClassName")
  9.                     {
  10.                         tt=t;
  11.                         methods = t.GetMethods();
  12.                     }
  13.                 }
  14.  
  15.                 for(int i=0;i<methods.Length;i++)
  16.                 {
  17.                     if(methods[i].DeclaringType==tt)
  18.                     {
  19.                         classA.Add(methods[i]);
  20.  
  21.                     }
  22.                 }
  23.                 foreach (MethodInfo m in classA)
  24.                 {
  25.  
  26.                     Console.WriteLine(m.Name);
  27.                 }
  28.  
Feb 13 '09 #2
vekipeki
229 Expert 100+
If you are writing the source for the loaded assembly also, you can also assign custom Attributes to your methods, and then filter them by attribute (just to distinguish between "important" and "unimportant" methods).

Example: http://msdn.microsoft.com/en-us/libr...tw(VS.80).aspx
Feb 13 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Derek Hart | last post by:
I wish to execute code from a string. The string will have a function name, which will return a string: Dim a as string a = "MyFunctionName(param1, param2)" I have seen a ton of people...
0
by: A. Wiebenga | last post by:
Hi all! I am a student at the Hogeschool van Arnhem en Nijmegen in Holland. I am currently involved in a research project regarding Reflection. Purpose of the research project is to document...
10
by: Sunny | last post by:
Hi, I have an old problem which I couldn't solve so far. Now I have found a post in that group that gave me an idea, but I can not fully understand it. The problem is: I'm trying to use a...
1
by: Mike Malter | last post by:
I am just starting to work with reflection and I want to create a log that saves relevant information if a method call fails so I can call that method again later using reflection. I am...
12
by: Antony | last post by:
Hello - I am wanting to print out a "Yes" next to classes that implement "Interface01", otherwise a "No". Here is my code. It crashes with a null reference exception and I am not sure why. Ideas?...
4
by: Bob | last post by:
If you rename a type at design time, the the task list shows what code broke, which happens to be a very nice list of dependant classes and methods. Is there any way to produce such dependency...
4
by: Doug Handler | last post by:
Hi, I've developed a plug-in application that basically is constructed of 2 pieces 1). the "main framework" 2). channels. Using Reflection in the Main Framework, i dynamically load Channels. ...
2
by: diego | last post by:
hi everyone, i have a sub that opens a form given the form's name as string and opens it using System.Reflection. How can I set the form's properties at runtime. Here is my code. Public Sub...
7
by: =?Utf-8?B?UVNJRGV2ZWxvcGVy?= | last post by:
I have a C# logging assembly with a static constructor and methods that is called from another C# Assembly that is used as a COM interface for a VB6 Application. Ideally I need to build a file...
6
by: =?Utf-8?B?c2lwcHl1Y29ubg==?= | last post by:
Hi I am slightly familiar with reflection but have never done the following I know how to find a class and call but I haven't done the following The Method return a List of Another Class And...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.