public void CreateInstanceFactoryT_TypeInfoNull_ArgExec() { // arrange // act Action action = () => ActivatorHelper .CompileFactory <object>(default(TypeInfo)); // assert Assert.Throws <ArgumentNullException>(action); }
public void CreateInstanceFactory_From_Class_With_Multiple_Constructors() { // arrange // act Action action = () => ActivatorHelper .CompileFactory(typeof(Foo).GetTypeInfo()); // assert Assert.Throws <InvalidOperationException>(action) .Message.MatchSnapshot(); }
public void CreateInstanceFactory_From_Interface() { // arrange // act Action action = () => ActivatorHelper .CompileFactory(typeof(IFoo).GetTypeInfo()); // assert Assert.Throws <InvalidOperationException>(action) .Message.MatchSnapshot(); }
public object?CreateInstance(Type type) { if (type is null) { throw new ArgumentNullException(nameof(type)); } try { return(ActivatorHelper.CompileFactory(type).Invoke(Services ?? _empty)); } catch (Exception ex) { throw new ServiceException( string.Format( UtilityResources.ServiceFactory_CreateInstanceFailed, type.FullName, CultureInfo.InvariantCulture), ex); } }