Follow me on Twitter at Twitter.com/wbm
FYI, I'm blogging most of my stuff over at More Wally now.
You might want to add my rss feed to your reader at:http://morewally.com/cs/blogs/wallym/rss.aspx
Simple Reflection in .NET Whidbey - Wallace B. McClure

Wallace B. McClure

All About Wally McClure - The musings of Wallym on Web, HTML5, Mobile, Xamarin.iOS, Xamarin.Android, and Windows Azure.

News

Visual Studio Magazine Column Personal Blog

.NET

Book Authors

Business

Family

Friends

Georgia Tech Bloggers

Personal

Archives

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;

 

Posted: Sep 24 2004, 08:43 PM by Wallym | with no comments
Filed under:

Comments

Patrick Steele said:

One suggestion: Get a new naming convention! Hungarian notation is so 20th-century. :)
# September 27, 2004 11:18 AM