1

How do you get all the reference dll name and their represent class name with namespace used in particular dll reflection in C#?

let us consider sample.dll in which reference1.dll and reference2.dll is used as reference to the sample dll through method reference1.method1 and reference2.method2

i need to list out

1)reference dll names ie.reference1.dll,reference2.dll
2)methods used in that dll names ie.reference1.method1,reference2.method2
3) Namespace used for referring that reference dll

i have tried with myassembly.GetTypes() it does no help me out

waiting for your responses

Michael
  • 57,169
  • 9
  • 80
  • 125
GowthamanSS
  • 1,434
  • 4
  • 33
  • 58
  • 1
    This might be of help: http://stackoverflow.com/questions/1593500/get-namespace-classname-from-a-dll-in-c-sharp-2-0 – Rob Apr 03 '13 at 12:28

1 Answers1

1

Hmm, I'm not sure why you think Assembly.GetTypes() doesn't help...

Note that not all dll's are on disk, so if you Assembly.Location instead of name then you may encounter an error.

Namespaces don't refer to a specific Assembly, an Assembly can contain many namespaces.

The method below will include a fair chunk of the .Net framework, so you may want to filter the list down a little bit.

Does this help?

        List<String> Dlls = new List<string>();
        List<String> Namespaces = new List<string>();
        List<String> Methods = new List<string>();
        foreach (var Assembly in AppDomain.CurrentDomain.GetAssemblies())
        {
            if (!Dlls.Contains(Assembly.GetName().Name))
                Dlls.Add(Assembly.GetName().Name);

            foreach (var Type in Assembly.GetTypes())
            {
                if (!Namespaces.Contains(Type.Namespace))
                    Namespaces.Add(Type.Namespace);
                foreach(var Method in Type.GetMethods())
                {
                    Methods.Add(String.Format("{0}.{1}", Type.Name, Method.Name));
                }
            }

        }
James
  • 9,774
  • 5
  • 34
  • 58