/// <summary> /// Creates an instance of the specified type using a generated factory to avoid using Reflection. /// </summary> /// <param name="type">The type to be created.</param> /// <returns>The newly created instance.</returns> public static object Create(string type) { var theType = Type.GetType(type); if (theType == null) { try { var typeInfo = type.Split(',').Select(info => info.Trim()).ToList(); theType = new Caching.AssemblyLoader(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $"{typeInfo[1]}.dll")).Assembly.GetExportedTypes().FirstOrDefault(serviceType => typeInfo[0].Equals(serviceType.ToString())); } catch (Exception ex) { Caching.Logger.Log <Caching.AssemblyLoader>(LogLevel.Information, LogLevel.Error, $"Error occurred while loading an assembly => {ex.Message}", ex); } } return(theType != null?FastActivator.Create(theType) : null); }
/// <summary> /// Creates an instance of the specified type using a generated factory to avoid using Reflection. /// </summary> /// <typeparam name="T">The type to be created.</typeparam> /// <returns>The newly created instance.</returns> public static T Create <T>() => (T)FastActivator.Create(typeof(T));