Simple Reflection in .NET Whidbey

Here is some simple Reflection code that I wrote to see what is in some .NET assemblies.  Suggestions are welcome.  Its not very "Whidbey-esque," but it gets the job done.

Wally

string strDotNetDir = @".......";

string strSql = String.Empty;

string strCn = ".....";

string strTypeOfType = String.Empty;

Assembly b = Assembly.LoadFrom(strDotNetDir + "System.Data.dll");

 

SqlConnection sqlCn = new SqlConnection(strCn);

SqlCommand sqlCm = new SqlCommand();

 

Type [] types = b.GetTypes ();

MethodInfo[] methods;

Type[] tInterfaces;

string[] strNames;

sqlCm.Connection = sqlCn;

sqlCm.CommandType = CommandType.Text;

sqlCn.Open();

foreach (Type t in types) {

      if ( t.IsPublic )

      {

            if (t.IsClass)

            {

            methods = t.GetMethods();

            foreach(MethodInfo m in methods)

            {

            //store the methods that were found.

            }

            }

            strTypeOfType = "Class";

        }

        if (t.IsEnum)

            {

            strNames = Enum.GetNames(t);

            foreach (string s in strNames)

            {

               //store the Enum names.

            }

            strTypeOfType = "Enum";

            }

        if (t.IsInterface)

        {

            tInterfaces = t.GetInterfaces();

            foreach (Type t2 in tInterfaces)

            {

               //store the interface(s) that were found.

            }

            strTypeOfType = "Interface";

        }

        if (strTypeOfType != String.Empty)

        {

         //do something with what you found as far as the type.

        }

        strTypeOfType = String.Empty;

    }

}

if ( sqlCn.State != ConnectionState.Closed )

{

      sqlCn.Close();

}

sqlCn.Dispose();

sqlCn = null;

sqlCm.Dispose();

sqlCm = null;

 

1 Comment

Comments have been disabled for this content.