public PrecompiledConstructor(Type type, Type[] constructorArgTypes) { if (type is null) { throw new ArgumentNullException(nameof(type)); } if (constructorArgTypes is null) { var ctor = type.GetConstructor(Type.EmptyTypes); if (ctor is null) { throw new Exception($"Constructor of type {type} with argument types passed cannot be found"); } this._activator = this.GenerateEmptyActivator(ctor); } else { var ctor = type.GetConstructor(constructorArgTypes); if (ctor is null) { throw new Exception($"Constructor of type {type} with argument types passed cannot be found"); } var @params = ctor.GetParameters(); this._activator = this.GenerateFilledActivator(ctor, @params); } }
public PrecompiledConstructor(ConstructorInfo constructor) { if (constructor is null) { throw new ArgumentNullException(nameof(constructor)); } var @params = constructor.GetParameters(); this._activator = @params is null || @params.Length == 0 ? this.GenerateEmptyActivator(constructor) : this.GenerateFilledActivator(constructor, @params); }