0

I am creating an object of the logger type dynamically, trying to use the concept of Reflection. My code is as follows.

public static ILogger Create(string loggerType)
{
            ILogger logger = null;

            string loggerValue = WebConfigurationManager.AppSettings.Get(loggerType);
            string[] loggerDll = loggerValue.Split(',');
            string[] loggerTypeValue = loggerDll[0].Split('.');

            Assembly asm = Assembly.Load(loggerTypeValue[0]);
            Type type = asm.GetType(loggerDll[1]);

            logger = (ILogger)Activator.CreateInstance(type);
            return logger;
}

I want to drop the use of Activator.CreateInstance() method. What is the alternative choice for me?

Maruthi Revankar
  • 331
  • 2
  • 5
  • 17
  • For what reason do you want to drop `Activator.CreateInstance` ? – YK1 Jul 24 '13 at 06:59
  • @YK1 That's because I have read that it's used with marshaling and it creates a wrapper object that isn't equal to the original object. – Maruthi Revankar Jul 26 '13 at 13:59
  • That is true for the `CreateInstance` overloads which return `ObjectHandle`, however, the overload you are using above returns `Object`. SO, I don't think you have to worry about it. – YK1 Jul 26 '13 at 15:02

0 Answers0