[Webinar] Streamline your web hosting managementRegister Today


C# Reflection MethodInfo problem

Posted on 2004-10-27
Medium Priority
Last Modified: 2008-03-03
I am having trouble of getting the desired method outputs.    I need to get the method infomation from the Euclid class as example:

int x 0
 string HowTo()
 int gcd(int, int)

but I am only getting the output as below:
System.String HowTo()
Int32 gcd(Int32, Int32)
System.Type GetType()

below is the code I have.  Your help will be very much appreciated!



public static void Main(string[] args)
Regex r = new Regex("(,)"); // Split on hyphens.
            string[] s = r.Split(args[0]);
            string unknownClass = s[0];
            string unknownDll = s[2];

            string dllPath = unknownDll + ".dll";
            Assembly UnknownAssembly = Assembly.LoadFrom(dllPath);
            Type type = UnknownAssembly.GetType(unknownClass);
            //Object obj = Activator.CreateInstance(type);

            Console.WriteLine("\nFollowing is the member info for class:{0} ",
           // BindingFlags flags = (BindingFlags.Public | BindingFlags.Instance);
            int count = 0;
            foreach (MethodInfo methodInfo in type.GetMethods(BindingFlags.Public | BindingFlags.Instance))
                // Print the Method Signature
                Console.WriteLine("{0}\t{1}", count, methodInfo);
            foreach (MemberInfo memberInfo in type.GetFields(BindingFlags.Public | BindingFlags.Instance))
                Console.WriteLine("{0}\t{1}",count, memberInfo);

namespace Edu.Rit.CS.ATS {
  /// <summary>
  ///   a relatively unknown test class.
  /// </summary>
  public class Euclid {
    public string HowTo () {
      return "to compute the greatest common divisor\n"
        +"\tset x and y and call gcd() or call gcd(x, y)";
    public int x, y;
    public int gcd (int x, int y) {
      while (x != y) if (x > y) x -= y; else y -= x;
      return x;
    public int gcd () { return gcd(x, y); }
    public int this [string name] {
      get {
        if (name == "x") return x;
        else if (name == "y") return y;
        else throw new IndexOutOfRangeException("only x or y");
      set {
        if (name == "x") x = value;
        else if (name == "y") y = value;
        else throw new IndexOutOfRangeException("only x or y");
    public int X { get { return x; } set { x = value; } }
    public int Y { get { return y; } set { y = value; } }

Question by:Charles Baldo
  • 2

Expert Comment

ID: 12432416
                 textBox3.Text = "";

                  Type t = typeof(Edu.Rit.CS.ATS.Euclid);
                  foreach(MethodInfo i in  t.GetMethods())
                        textBox3.Text += i.Name.ToString()+"(";
                        string s="";
                        foreach(ParameterInfo p in i.GetParameters())
                              s+= p.ParameterType.ToString()+" "+p.Name+",";
                        if (s.Length>0)      s=s.Substring(0,s.Length-1);
                        textBox3.Text += s+")"+"\r\n";                        

Accepted Solution

God_Ares earned 1500 total points
ID: 12432420
              Type t = typeof(Edu.Rit.CS.ATS.Euclid);

can be done your way,...

Assembly UnknownAssembly = Assembly.LoadFrom(dllPath);
            Type type = UnknownAssembly.GetType(unknownClass);

als long if unknownClass == "Edu.Rit.CS.ATS.Euclid"

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…
Planning to migrate your EDB file(s) to a new or an existing Outlook PST file? This video will guide you how to convert EDB file(s) to PST. Besides this, it also describes, how one can easily search any item(s) from multiple folders or mailboxes…

608 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