public CompilableTypeConverterByPropertySettingFactory(
            ICompilablePropertyGetterFactory propertyGetterFactory,
            PropertySettingTypeOptions propertySettingType,
            IEnumerable <PropertyInfo> propertiesToIgnore,
            ByPropertySettingNullSourceBehaviourOptions nullSourceBehaviour,
            IEnumerable <PropertyInfo> initialisedFlagsIfTranslatingNullsToEmptyInstances)
        {
            if (propertyGetterFactory == null)
            {
                throw new ArgumentNullException("propertyGetterFactory");
            }
            if (!Enum.IsDefined(typeof(PropertySettingTypeOptions), propertySettingType))
            {
                throw new ArgumentOutOfRangeException("propertySettingType");
            }
            if (propertiesToIgnore == null)
            {
                throw new ArgumentNullException("propertiesToIgnore");
            }
            if (!Enum.IsDefined(typeof(ByPropertySettingNullSourceBehaviourOptions), nullSourceBehaviour))
            {
                throw new ArgumentOutOfRangeException("nullSourceBehaviour");
            }
            if (initialisedFlagsIfTranslatingNullsToEmptyInstances == null)
            {
                throw new ArgumentNullException("initialisedFlagsIfTranslatingNullsToEmptyInstances");
            }
            if ((nullSourceBehaviour != ByPropertySettingNullSourceBehaviourOptions.CreateEmptyInstanceWithDefaultPropertyValues) && initialisedFlagsIfTranslatingNullsToEmptyInstances.Any())
            {
                throw new ArgumentException("initialisedFlagsIfTranslatingNullsToEmptyInstances must be empty if nullSourceBehaviour is not CreateEmptyInstanceWithDefaultPropertyValues");
            }

            _propertyGetterFactory = propertyGetterFactory;
            _propertySettingType   = propertySettingType;
            _propertiesToIgnore    = new HashSet <PropertyInfo>(propertiesToIgnore);
            if (_propertiesToIgnore.Any(p => p == null))
            {
                throw new ArgumentException("Null reference encountered in propertiesToIgnore set");
            }
            _nullSourceBehaviour = nullSourceBehaviour;
            _initialisedFlagsIfTranslatingNullsToEmptyInstances = initialisedFlagsIfTranslatingNullsToEmptyInstances.ToList().AsReadOnly();
            if (_initialisedFlagsIfTranslatingNullsToEmptyInstances.Any(p => p == null))
            {
                throw new ArgumentException("Null reference encountered in initialisedFlagsIfTranslatingNullToEmptyInstance set");
            }
            if (_initialisedFlagsIfTranslatingNullsToEmptyInstances.Any(p => (p.PropertyType != typeof(bool)) && (p.PropertyType != typeof(bool?))))
            {
                throw new ArgumentException("Encountered invalid property in initialisedFlagsIfTranslatingNullToEmptyInstance set, PropertyType must be bool or nullable bool");
            }
        }
        public ConverterWrapper(ByPropertySettingNullSourceBehaviourOptions nullSourceBehaviour, EnumerableSetNullHandlingOptions enumerableSetNullHandling)
        {
            if (!Enum.IsDefined(typeof(ByPropertySettingNullSourceBehaviourOptions), nullSourceBehaviour))
            {
                throw new ArgumentOutOfRangeException("nullSourceBehaviour");
            }
            if (!Enum.IsDefined(typeof(EnumerableSetNullHandlingOptions), enumerableSetNullHandling))
            {
                throw new ArgumentOutOfRangeException("enumerableSetNullHandling");
            }

            _nullSourceBehaviour       = nullSourceBehaviour;
            _enumerableSetNullHandling = enumerableSetNullHandling;
            _allPropertiesToIgnoreToPropertySetterConversions      = new List <PropertyInfo>();
            _allInitialisedFlagsIfTranslatingNullsToEmptyInstances = new List <PropertyInfo>();
            _converterCache = new Dictionary <Tuple <Type, Type>, object>();

            // Prepare converter factories (for by-constructor and by-property-setters) using the base types (AssignableType and
            // EnumConversion property getter factories)
            var nameMatcher = new CaseInsensitiveSkipUnderscoreNameMatcher();
            var basePropertyGetterFactories = new ICompilablePropertyGetterFactory[]
            {
                new CompilableAssignableTypesPropertyGetterFactory(nameMatcher),
                new CompilableEnumConversionPropertyGetterFactory(nameMatcher)
            };

            _constructorBasedConverterFactory = ExtendableCompilableTypeConverterFactoryHelpers.GenerateConstructorBasedFactory(
                nameMatcher,
                new ArgsLengthTypeConverterPrioritiserFactory(),
                basePropertyGetterFactories,
                _enumerableSetNullHandling
                );
            _propertySetterBasedConverterFactory = ExtendableCompilableTypeConverterFactoryHelpers.GeneratePropertySetterBasedFactory(
                nameMatcher,
                CompilableTypeConverterByPropertySettingFactory.PropertySettingTypeOptions.MatchAll,
                basePropertyGetterFactories,
                _allPropertiesToIgnoreToPropertySetterConversions,
                _nullSourceBehaviour,
                _allInitialisedFlagsIfTranslatingNullsToEmptyInstances,
                _enumerableSetNullHandling
                );
        }
Example #3
0
        public CompilableTypeConverterByConstructorFactory(
            ITypeConverterPrioritiserFactory constructorPrioritiserFactory,
            ICompilablePropertyGetterFactory propertyGetterFactory,
            ParameterLessConstructorBehaviourOptions parameterLessConstructorBehaviour)
        {
            if (constructorPrioritiserFactory == null)
            {
                throw new ArgumentNullException("constructorPrioritiserFactory");
            }
            if (propertyGetterFactory == null)
            {
                throw new ArgumentNullException("propertyGetterFactory");
            }
            if (!Enum.IsDefined(typeof(ParameterLessConstructorBehaviourOptions), parameterLessConstructorBehaviour))
            {
                throw new ArgumentOutOfRangeException("parameterLessConstructorBehaviour");
            }

            _constructorPrioritiserFactory     = constructorPrioritiserFactory;
            _propertyGetterFactory             = propertyGetterFactory;
            _parameterLessConstructorBehaviour = parameterLessConstructorBehaviour;
        }