/// <summary>
        /// Method that creates a student instance,
        /// class name loaded from App.Config, and created by reflection.
        /// </summary>
        /// <returns></returns>
        public static SchoolMember CreateSchoolMember()
        {
            //Get full name of class, make sure System.Configuration is added to reference and using statement.
            string fullname = ConfigurationManager.AppSettings.Get("Student");
            //Get instance by reflection, creates a student in this case.
            SchoolMember student = (SchoolMember)Activator.CreateInstance(null, fullname).Unwrap();

            //return the instance
            return(student);
        }
Example #2
0
 public static void TestSimpleFactory()
 {
     //Use factory to create a student instance
     Simple_Factory.SchoolMember s = Simple_Factory.SchoolFactory.CreateSchoolMember();
     //Set properties
     s.Id   = 50;
     s.Name = "Jack";
     //Print them out.
     Console.WriteLine("Id:{0} Name:{1}", s.Id, s.Name);
 }