Search member method in Assembly : Assembly « Reflection « C# / CSharp Tutorial






using System;
using System.Reflection;
using System.IO;
using System.Collections;

    class Class1
    {
        [STAThread]
        static int Main(string[] args)
        {
            ArrayList filterStrings = new ArrayList();
            filterStrings.Add("your value");
            Assembly asm = Assembly.LoadFile( "assembly file" );
            MemberFilter filter = new MemberFilter( OnCustomSearch );

            foreach( Module module in asm.GetModules() )
            {
                foreach( Type t in module.GetTypes() )
                {
                    if( filterStrings.Contains( t.Name ) )
                        Console.WriteLine( "Found type {0}", t.Name );

                    MemberInfo[] foundMembers = t.FindMembers( MemberTypes.All, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly,
                        filter, filterStrings );

                    foreach( MemberInfo member in foundMembers )
                    {
                        Console.WriteLine( "Found member {0} which is a {1} defined in {2}.", member.Name, member.MemberType, t.Name );
                    }
                }
            }
            return 0;
        }

        public static bool OnCustomSearch( MemberInfo member, object filter )
        {
            ArrayList al = (ArrayList) filter;
            if( al.Contains( member.Name ))
                return true;

            if( al.Contains( member.MemberType ))
                return true;

            return false;
        }
    }








19.12.Assembly
19.12.1.Load Assembly from Dll
19.12.2.Reflecting An Assembly
19.12.3.Reflecting On A Type
19.12.4.Execute Assembly
19.12.5.Search member method in Assembly
19.12.6.Assembly Tree Viewer
19.12.7.DefineDynamicAssembly method and AssemblyResolve event.
19.12.8.Assembly makes internal types and internal members visible to the assembly called your_assemblies.
19.12.9.Use the file name to load the assembly into the current application domain.