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
ASP.NET Podcast Show #57 - Wally on Interfaces - Wallace B. McClure

Wallace B. McClure

All About Wally McClure - The musings of Wallym on Web, HTML5, Mobile, MonoTouch for iPhone, MonoDroid for Android, and Windows Azure.

News

Personal Blog

Work Blog

.NET

Book Authors

Business

Family

Friends

Georgia Tech Bloggers

Personal

Archives

ASP.NET Podcast Show #57 - Wally on Interfaces

Subscribe.  You KNOW you want it.

 

Download.  Kinda like your father’s Oldsmobile.

 

URL: http://aspnetpodcast.com/CS11/blogs/asp.net_podcast/archive/2006/06/29/340.aspx

 

Show Notes:

namespace CallingInterface

{

      /// <summary>

      /// Summary description for Class1.

      /// </summary>

      public interface ICalling

      {

            bool GetConfig();

            bool Start();

            bool Stop();

            string Test();

            string ConfigFileLocation

            {

                  set;

                  get;

            }

      }

}

Dynamic Loading & Calling a mehod
      string strConfigFile;

      string strType = String.Empty;

      ArrayList aryListClassInfo;

      cLoader objLoad = new cLoader();

      AssemblyTypeClassInfo atci;

      strConfigFile = objLoad.GetConfigFile();

      Assembly assembly;

      aryListClassInfo = objLoad.LoadAssemblyInfoConfigFile(strConfigFile);

      aryListClassInfo = objLoad.LoadAssemblyInfoConfigFile(strConfigFile);

      foreach(Object obj in aryListClassInfo)

      {

            atci = (AssemblyTypeClassInfo)obj;

            assembly = Assembly.LoadFile(System.Windows.Forms.Application.StartupPath + @"\" + atci.AssemblyLocation);

            if (null != assembly)

            {

                  foreach(Type typDyn in assembly.GetTypes())

                  {

                        if ((typDyn.FullName == atci.ClassName) && (typDyn.IsClass == true))

                        {

                              try

                              {

                                    object objClass = Activator.CreateInstance(typDyn);

                                    if ( objClass is CallingInterface.ICalling  )

                                    {

                                          atci.TypeOfObject = typDyn;

                                          atci.objRef = objClass;

                                          typDyn.InvokeMember("ConfigFileLocation", BindingFlags.SetProperty | BindingFlags.Default, null, objClass, new Object[] {strConfigFile}); // Set a property

                                          object Result = typDyn.InvokeMember("GetConfig", BindingFlags.Default | BindingFlags.InvokeMethod, null, objClass, null);  // Call a method.

                                          Result = typDyn.InvokeMember("Start", BindingFlags.Default | BindingFlags.InvokeMethod, null, objClass, null);  // Call another method.

                                    }

                              }

                              catch(Exception exc)

                              {

                                    Console.WriteLine("Exception: " + exc.Message);

                              }

                              finally

                              {

                              }

                        }

                  }

            }

      }

Comments

No Comments

Leave a Comment

(required) 

(required) 

(optional)

(required)