jeudi 21 janvier 2016

Obtaining method signatures types and names

I'm writing a 'quick' c# application that will allow me to see all the Methods avaliable under an Assembly DLL, so far all is well and i can output the class, access modifier and name :

    private void btnListMethodName()
    {
        string sAssemblyFileName = assemblyLocation.Text;

        if (sAssemblyFileName.Length != 0)
        {
            Assembly assem = Assembly.LoadFrom(sAssemblyFileName);
            Type[] types = assem.GetTypes();
            ArrayList arrl = new ArrayList();

            foreach (Type cls in types)
            {

                try
                {
                    //Add Class Name                       
                    arrl.Add(cls.FullName);
                    if (cls.IsAbstract)
                        arrl.Add("Abstract Class:" + cls.Name.ToString());
                    else if (cls.IsPublic)
                        arrl.Add("Public Class:" + cls.Name.ToString());
                    else if (cls.IsSealed)
                        arrl.Add("Sealed Class:" + cls.Name.ToString());

                    MemberInfo[] methodName = cls.GetMethods();

                    foreach (MemberInfo method in methodName)
                    {
                        method.ReflectedType.GetProperties();
                        if (method.ReflectedType.IsPublic)
                            arrl.Add("\tPublic - " + method.Name.ToString());
                        else
                            arrl.Add("\tNon-Public - " + method.Name.ToString());
                    }
                }
                catch (System.NullReferenceException)
                {
                    Console.WriteLine("Error msg");
                }
            }
            olvMain.SetObjects(arrl);

            for (int i = 0; i < arrl.Count; i++)
            {
                AssemblyList.Items.Add(arrl[i].ToString());
            }
        }
    }

What i now need to output is the datatype and name of the methods signature values. For example, at the moment i output 'Public - methodName' what i would like to output is 'Public - methodName(string methodData, int methodData2)'

Is this possible?





Aucun commentaire:

Enregistrer un commentaire