ttajic
1/23/2017 - 2:14 PM

Create Instance of a class with class name (dynamic instance creation)

Create Instance of a class with class name (dynamic instance creation)

        public static T LoadClass<T>(string assemblyName, string className, params object[] constructorParameters)
        { 
            T response;
            Assembly asm = Assembly.Load(assemblyName);
            Type targetType = asm.GetType(className);
            response = (T)Activator.CreateInstance(targetType, constructorParameters);
            return response;
        }
        public static T LoadClass<T>(string assemblyName, string className)
        {
            T response;
            Assembly asm = Assembly.Load(assemblyName);
            Type targetType = asm.GetType(className);
            response = (T)Activator.CreateInstance(targetType);
            return response;
        }