/// <summary> /// This will return null if unable to return a PropertyInfo instance for the named property that will return a value as the requested type /// </summary> private PropertyInfo getProperty(Type srcType, string name, INameMatcher nameMatcher, Type destPropertyType) { if (srcType == null) { throw new ArgumentNullException("srcType"); } name = (name ?? "").Trim(); if (name == "") { throw new ArgumentException("Null/blank name specified"); } if (nameMatcher == null) { throw new ArgumentNullException("nameMatcher"); } if (destPropertyType == null) { throw new ArgumentNullException("destPropertyType"); } return(srcType.GetProperties().FirstOrDefault(p => p.GetIndexParameters().Length == 0 && nameMatcher.IsMatch(name, p.Name) && canMap(p.PropertyType, destPropertyType) )); }
public ConfigurationData( INameMatcher nameMatcher, IEnumerable <ICompilablePropertyGetterFactory> basePropertyGetterFactories, ConverterFactoryGenerator converterFactoryGenerator, IPropertyGetterFactoryExtrapolator propertyGetterFactoryExtrapolator) { if (nameMatcher == null) { throw new ArgumentNullException("nameMatcher"); } if (basePropertyGetterFactories == null) { throw new ArgumentNullException("basePropertyGetterFactories"); } if (converterFactoryGenerator == null) { throw new ArgumentNullException("converterFactoryGenerator"); } if (propertyGetterFactoryExtrapolator == null) { throw new ArgumentNullException("propertyGetterFactoryExtrapolator"); } NameMatcher = nameMatcher; BasePropertyGetterFactories = basePropertyGetterFactories.ToList().AsReadOnly(); if (BasePropertyGetterFactories.Any(f => f == null)) { throw new ArgumentException("Null reference encountered in basePropertyGetterFactories set"); } ConverterFactoryGenerator = converterFactoryGenerator; PropertyGetterFactoryExtrapolator = propertyGetterFactoryExtrapolator; }
public ExceptionMessageDoesNotMatchException( INameMatcher matcher, Exception innerException ) :base( String.Format("Exception message {0} does not match {1}", innerException.Message, matcher), innerException) { }
public ExceptionMessageDoesNotMatchException( INameMatcher matcher, Exception innerException ) : base( String.Format("Exception message {0} does not match {1}", innerException.Message, matcher), innerException) { }
public CompilableAssignableTypesPropertyGetterFactory(INameMatcher nameMatcher) { if (nameMatcher == null) { throw new ArgumentNullException("nameMatcher"); } _nameMatcher = nameMatcher; }
/// <summary> /// Initializes a new instance of the <see cref="DefaultSelectorResolver"/> class. /// </summary> public DefaultSelectorResolver(ISelectorFactory selectorFactory, IDescriptorRepository descriptorRepository, INameMatcher nameMatcher = null) { Assume.NotNull(selectorFactory, nameof(selectorFactory)); Assume.NotNull(descriptorRepository, nameof(descriptorRepository)); SelectorFactory = selectorFactory; DescriptorRepository = descriptorRepository; NameMatcher = nameMatcher ?? new EqualityNameMatcher(); }
public CompilableEnumConversionPropertyGetterFactory(INameMatcher nameMatcher) { if (nameMatcher == null) { throw new ArgumentNullException("nameMatcher"); } _nameMatcher = nameMatcher; }
/// <summary> /// Initializes a new instance of the <see cref="DefaultRunnableFactory"/> class. /// </summary> public DefaultRunnableFactory(IEnumerable <Type> availableRunnables, IValueConverter valueConverter = null, INameMatcher runnableNameMatcher = null, INameMatcher parameterNameMatcher = null, IServiceFactory serviceFactory = null) { AvailableRunnables = availableRunnables ?? Enumerable.Empty <Type>(); RunnableNameMatcher = runnableNameMatcher ?? new EqualityNameMatcher(); ParameterNameMatcher = parameterNameMatcher ?? new EqualityNameMatcher(); ValueConverter = valueConverter ?? new EmptyValueConverter(); ServiceFactory = serviceFactory; }
/// <summary> /// Initializes a new instance of the <see cref="DefaultRunnableFactory"/> class. /// </summary> public DefaultRunnableFactory(IEnumerable<Type> availableRunnables, IValueConverter valueConverter = null, INameMatcher runnableNameMatcher = null, INameMatcher parameterNameMatcher = null, IServiceFactory serviceFactory = null) { AvailableRunnables = availableRunnables ?? Enumerable.Empty<Type>(); RunnableNameMatcher = runnableNameMatcher ?? new EqualityNameMatcher(); ParameterNameMatcher = parameterNameMatcher ?? new EqualityNameMatcher(); ValueConverter = valueConverter ?? new EmptyValueConverter(); ServiceFactory = serviceFactory; }
/// <summary> /// This will return an ExtendableCompilableTypeConverterFactory based around the destination types having a zero parameter constructor and /// its data being set through public properties /// </summary> public static ExtendableCompilableTypeConverterFactory GeneratePropertySetterBasedFactory( INameMatcher nameMatcher, CompilableTypeConverterByPropertySettingFactory.PropertySettingTypeOptions propertySettingTypeOptions, IEnumerable <ICompilablePropertyGetterFactory> basePropertyGetterFactories, IEnumerable <PropertyInfo> propertiesToIgnore, ByPropertySettingNullSourceBehaviourOptions nullSourceBehaviour, IEnumerable <PropertyInfo> initialisedFlagsIfTranslatingNullsToEmptyInstances, EnumerableSetNullHandlingOptions enumerableSetNullHandling) { if (nameMatcher == null) { throw new ArgumentNullException("nameMatcher"); } if (!Enum.IsDefined(typeof(CompilableTypeConverterByPropertySettingFactory.PropertySettingTypeOptions), propertySettingTypeOptions)) { throw new ArgumentOutOfRangeException("propertySettingTypeOptions"); } if (basePropertyGetterFactories == null) { throw new ArgumentNullException("basePropertyGetterFactories"); } if (propertiesToIgnore == null) { throw new ArgumentNullException("propertiesToIgnore"); } if (initialisedFlagsIfTranslatingNullsToEmptyInstances == null) { throw new ArgumentNullException("initialisedFlagsIfTranslatingNullsToEmptyInstances"); } if (!Enum.IsDefined(typeof(ByPropertySettingNullSourceBehaviourOptions), nullSourceBehaviour)) { throw new ArgumentOutOfRangeException("nullSourceBehaviour"); } if (!Enum.IsDefined(typeof(EnumerableSetNullHandlingOptions), enumerableSetNullHandling)) { throw new ArgumentOutOfRangeException("enumerableSetNullHandling"); } return(new ExtendableCompilableTypeConverterFactory( nameMatcher, basePropertyGetterFactories, propertyGetterFactories => new CompilableTypeConverterByPropertySettingFactory( // Define a ConverterFactoryGenerator to return a CompilableTypeConverterByPropertySettingFactory when new conversions are registered new CombinedCompilablePropertyGetterFactory(propertyGetterFactories), propertySettingTypeOptions, propertiesToIgnore, nullSourceBehaviour, initialisedFlagsIfTranslatingNullsToEmptyInstances ), new CompilableTypeConverterPropertyGetterFactoryExtrapolator( nameMatcher, enumerableSetNullHandling ) )); }
public AutoMapperEnabledPropertyGetterFactory(INameMatcher nameMatcher, IConfigurationProvider mappingConfig) { if (nameMatcher == null) { throw new ArgumentNullException("nameMatcher"); } if (mappingConfig == null) { throw new ArgumentNullException("mappingConfig"); } _nameMatcher = nameMatcher; _mappingConfig = mappingConfig; }
public CompilableTypeConverterPropertyGetterFactoryExtrapolator(INameMatcher nameMatcher, EnumerableSetNullHandlingOptions enumerableSetNullHandling) { if (nameMatcher == null) { throw new ArgumentNullException("nameMatcher"); } if (!Enum.IsDefined(typeof(EnumerableSetNullHandlingOptions), enumerableSetNullHandling)) { throw new ArgumentOutOfRangeException("enumerableSetNullHandling"); } _nameMatcher = nameMatcher; _enumerableSetNullHandling = enumerableSetNullHandling; }
public CompilableTypeConverterPropertyGetterFactory(INameMatcher nameMatcher, ICompilableTypeConverter <TPropertyOnSource, TPropertyAsRetrieved> typeConverter) { if (nameMatcher == null) { throw new ArgumentNullException("nameMatcher"); } if (typeConverter == null) { throw new ArgumentNullException("typeConverter"); } _nameMatcher = nameMatcher; _typeConverter = typeConverter; }
private void VerifyException(Exception ex) { if (String.IsNullOrEmpty(this.Attribute.MessagePattern)) { return; } INameMatcher matcher = NameMatcherFactory.CreateMatcher( this.Attribute.MessageMatchType, this.Attribute.MessagePattern); if (!matcher.IsMatch(ex.Message)) { throw new ExceptionMessageDoesNotMatchException(matcher, ex); } }
public override void Run(object fixture) { System.Runtime.CompilerServices.RuntimeHelpers.PrepareConstrainedRegions(); try { this.TestCase.Run(fixture); } finally { // looking for processes to kill INameMatcher matcher = NameMatcherFactory.CreateMatcher(this.Attribute.MatchType, this.Attribute.Name); foreach (Process p in Process.GetProcesses()) { if (matcher.IsMatch(p.ProcessName)) { Console.WriteLine("Killing {0} {1}", p.Id, p.ProcessName); p.Kill(); } } } }
public EnumerableCompilablePropertyGetterFactory( INameMatcher nameMatcher, ICompilableTypeConverter <TPropertyOnSourceElement, TPropertyAsRetrievedElement> typeConverter, EnumerableSetNullHandlingOptions enumerableSetNullHandling) { if (nameMatcher == null) { throw new ArgumentNullException("nameMatcher"); } if (typeConverter == null) { throw new ArgumentNullException("typeConverter"); } if (!Enum.IsDefined(typeof(EnumerableSetNullHandlingOptions), enumerableSetNullHandling)) { throw new ArgumentOutOfRangeException("enumerableSetNullHandling"); } _nameMatcher = nameMatcher; _typeConverter = typeConverter; _enumerableSetNullHandling = enumerableSetNullHandling; }
/// <summary> /// This will return an ExtendableCompilableTypeConverterFactory that is based around the destination types being instantiated by constructor. Note /// that this method has less options than GeneratePropertySetterBasedFactory since by-property-setter translation may be used in more scenarios /// that the by-constructor translations and with more specific configurations (eg. by-constructor translations can't be used in Entity Framework /// IQueryable mappings since constructors with parameters can not be used - the nullSourceBehaviour and enumerableSetNullHandling options are /// to tailor conversions to work with such IQueryable translations). /// </summary> public static ExtendableCompilableTypeConverterFactory GenerateConstructorBasedFactory( INameMatcher nameMatcher, ITypeConverterPrioritiserFactory converterPrioritiser, IEnumerable <ICompilablePropertyGetterFactory> basePropertyGetterFactories, EnumerableSetNullHandlingOptions enumerableSetNullHandling) { if (nameMatcher == null) { throw new ArgumentNullException("nameMatcher"); } if (converterPrioritiser == null) { throw new ArgumentNullException("converterPrioritiser"); } if (basePropertyGetterFactories == null) { throw new ArgumentNullException("basePropertyGetterFactories"); } if (!Enum.IsDefined(typeof(EnumerableSetNullHandlingOptions), enumerableSetNullHandling)) { throw new ArgumentOutOfRangeException("enumerableSetNullHandling"); } return(new ExtendableCompilableTypeConverterFactory( nameMatcher, basePropertyGetterFactories, propertyGetterFactories => new CompilableTypeConverterByConstructorFactory( // Define a ConverterFactoryGenerator to return a CompilableTypeConverterByConstructorFactory when new conversions are registered converterPrioritiser, new CombinedCompilablePropertyGetterFactory(propertyGetterFactories), ParameterLessConstructorBehaviourOptions.Ignore ), new CompilableTypeConverterPropertyGetterFactoryExtrapolator( nameMatcher, enumerableSetNullHandling ) )); }
public ExtendableCompilableTypeConverterFactory( INameMatcher nameMatcher, IEnumerable <ICompilablePropertyGetterFactory> basePropertyGetterFactories, ConverterFactoryGenerator converterFactoryGenerator, IPropertyGetterFactoryExtrapolator propertyGetterFactoryExtrapolator) { if (nameMatcher == null) { throw new ArgumentNullException("nameMatcher"); } if (basePropertyGetterFactories == null) { throw new ArgumentNullException("basePropertyGetterFactories"); } if (converterFactoryGenerator == null) { throw new ArgumentNullException("converterFactoryGenerator"); } if (propertyGetterFactoryExtrapolator == null) { throw new ArgumentNullException("propertyGetterFactoryExtrapolator"); } // Record all these settings in a ConfigurationData instance rather than duplicating the check-for-null-property-getter-factories logic here _configurationData = new ConfigurationData( nameMatcher, basePropertyGetterFactories, converterFactoryGenerator, propertyGetterFactoryExtrapolator ); _typeConverterFactory = converterFactoryGenerator(_configurationData.BasePropertyGetterFactories); if (_typeConverterFactory == null) { throw new Exception("Specified converterFactoryGenerator returned null"); } }