public T CreateParser <T>() { var parserType = typeof(T); if (!parserType.HasParameterlessConstructor()) { throw CreatingValueParserFailedException.CannotCreateInActivatorFactory(parserType); } return(Activator.CreateInstance <T>()); }
private IValueParser CreateExternalParser(Type parserType) { var factoryType = _valueParserFactory.GetType(); var method = factoryType.GetMethod(nameof(IValueParserFactory.CreateParser)); // ReSharper disable once PossibleNullReferenceException var generic = method.MakeGenericMethod(parserType); try { return((IValueParser)generic.Invoke(_valueParserFactory, null)); } catch (TargetInvocationException ex) when(ex.InnerException is CreatingValueParserFailedException) { throw ex.InnerException; } catch (TargetInvocationException ex) { throw CreatingValueParserFailedException.CreatingFailed(factoryType, parserType, ex); } }