C# Reflection MethodInfo problem

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!

     Thanks!


************************************

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} ",
                                   unknownClass);
           // 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);
                count++;
            }
           
            foreach (MemberInfo memberInfo in type.GetFields(BindingFlags.Public | BindingFlags.Instance))
            {
                Console.WriteLine("{0}\t{1}",count, memberInfo);
                count++;
            }
}

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; } }
  }
}

                             
Charles BaldoSoftware DeveloperAsked:
Who is Participating?
 
God_AresCommented:
              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"
0
 
God_AresCommented:
                 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";                        
                  }
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.