public SimpleTypeConverterByConstructorFactory( ITypeConverterPrioritiserFactory constructorPrioritiserFactory, IConstructorInvokerFactory constructorInvokerFactory, IPropertyGetterFactory propertyGetterFactory, ParameterLessConstructorBehaviourOptions parameterLessConstructorBehaviour) { if (constructorPrioritiserFactory == null) { throw new ArgumentNullException("constructorPrioritiserFactory"); } if (constructorInvokerFactory == null) { throw new ArgumentNullException("constructorInvokerFactory"); } if (propertyGetterFactory == null) { throw new ArgumentNullException("propertyGetterFactory"); } if (!Enum.IsDefined(typeof(ParameterLessConstructorBehaviourOptions), parameterLessConstructorBehaviour)) { throw new ArgumentOutOfRangeException("parameterLessConstructorBehaviour"); } _constructorPrioritiserFactory = constructorPrioritiserFactory; _constructorInvokerFactory = constructorInvokerFactory; _propertyGetterFactory = propertyGetterFactory; _parameterLessConstructorBehaviour = parameterLessConstructorBehaviour; }
/// <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 ) )); }