ASP.NET Podcast

ASP.NET Podcast is geared towards the Microsoft .NET Framework and ASP.NET.
The podcast is run by Wally McClure, David Penton, and Paul Glavich.
Welcome to ASP.NET Podcast Sign in | Join | Help
in Search

ASP.NET Podcast

The ASP.NET Podcast features, technical talks, interviews, news, reviews, and Wallyisms. Wallace B. (Wally) McClure, David Penton, and Paul Glavich are your hosts. We talk about ASP.NET, AJAX, Performance, Databases, WCF, Silverlight, Cloud Computing, Windows Azure, and whatever else we decide to talk about.

ASP.NET Podcast Show #57 - Wally on Interfaces

Subscribe.  You KNOW you want it.

 

This show is available in the subscription feed.

 

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

                              {

                              }

                        }

                  }

            }

      }

Published Thursday, June 29, 2006 10:48 PM by admin
Anonymous comments are disabled

This Blog

Syndication

Powered by Community Server, by Telligent Systems