[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

C# Reflection MethodInfo problem

Posted on 2004-10-27
2
Medium Priority
?
1,441 Views
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!

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

                             
0
Comment
Question by:Charles Baldo
[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
  • 2
2 Comments
 
LVL 7

Expert Comment

by:God_Ares
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";                        
                  }
0
 
LVL 7

Accepted Solution

by:
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"
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
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…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

656 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