ASP.NET Podcast Show #57 - Wally on Interfaces

Wally pumps out another podcast.

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

                              {

                              }

                        }

                  }

            }

      }

No Comments