コード例 #1
0
ファイル: Parameter.cs プロジェクト: NaseUkolyCZ/HarshPoint
        internal Parameter(
            PropertyAccessor propertyAccessor,
            ParameterAttribute parameterAttribute,
            IDefaultValuePolicy defaultValuePolicy
        )
        {
            if (propertyAccessor == null)
            {
                throw Logger.Fatal.ArgumentNull(nameof(propertyAccessor));
            }

            if (parameterAttribute == null)
            {
                throw Logger.Fatal.ArgumentNull(nameof(parameterAttribute));
            }

            if (defaultValuePolicy == null)
            {
                throw Logger.Fatal.ArgumentNull(nameof(defaultValuePolicy));
            }

            PropertyAccessor = propertyAccessor;
            ParameterAttribute = parameterAttribute;
            DefaultValuePolicy = defaultValuePolicy;

            ValidationAttributes = PropertyAccessor.PropertyInfo
                .GetCustomAttributes<ParameterValidationAttribute>(inherit: true)
                .ToImmutableArray();
        }
コード例 #2
0
        public static Boolean IsResolveType(PropertyAccessor property)
        {
            if (property == null)
            {
                throw Logger.Fatal.ArgumentNull(nameof(property));
            }

            return IsResolveType(property.PropertyTypeInfo);
        }
コード例 #3
0
        private static Boolean IsBothCommonParameterAndInParameterSet(
            PropertyAccessor property,
            IEnumerable <ParameterAttribute> attributes
            )
        {
            if (attributes.Any(a => a.ParameterSetName == null))
            {
                if (attributes.Count() > 1)
                {
                    throw Logger.Fatal.ObjectMetadata(
                              SR.HarshProvisionerMetadata_ParameterBothCommonAndInSet,
                              property.DeclaringType,
                              property.Name
                              );
                }
            }

            return(false);
        }
コード例 #4
0
        private Boolean IsMandatoryAndUnsupportedByDefaultValuePolicy(
            PropertyAccessor property,
            IEnumerable <ParameterAttribute> attributes
            )
        {
            if (!DefaultValuePolicy.SupportsType(property.PropertyTypeInfo) &&
                attributes.Any(a => a.Mandatory))
            {
                throw Logger.Fatal.ObjectMetadata(
                          SR.HarshProvisionerMetadata_MandatoryTypeNotSupportedByDefaultValuePolicy,
                          property.DeclaringType,
                          property.Name,
                          property.PropertyType,
                          DefaultValuePolicy.GetType()
                          );
            }

            return(false);
        }
コード例 #5
0
        public DefaultFromContextProperty(
            PropertyAccessor accessor,
            DefaultFromContextAttribute attribute
        )
        {
            if (accessor == null)
            {
                throw Logger.Fatal.ArgumentNull(nameof(accessor));
            }

            if (attribute == null)
            {
                throw Logger.Fatal.ArgumentNull(nameof(attribute));
            }

            Accessor = accessor;
            Attribute = attribute;
            ResolvedPropertyInfo = ResolvedPropertyTypeInfo.TryParse(PropertyTypeInfo);

            ValidateIsNullable();
            ValidateTagTypeIsIDefaultFromContextTag();
            ValidateWithTagNotResolvable();
        }
コード例 #6
0
        private static Object CreateResult(
            PropertyAccessor property,
            IResolveBuilder resolveBuilder,
            IEnumerable resultSource,
            IEnumerable<ResolveFailure> failureSource
        )
        {
            if (resultSource == null)
            {
                Logger.Warning(
                    "Property {PropertyName} resolver {$Resolver} resolved into null value.",
                    property.Name,
                    resolveBuilder
                );

                return null;
            }

            var result = ResolveResultFactory.CreateResult(
                property.PropertyTypeInfo,
                resultSource,
                resolveBuilder,
                failureSource
            );

            Logger.Debug(
                "Property {PropertyName} resolver {$Resolver} result adapted into {$Value}, assigning.",
                property.Name,
                resolveBuilder,
                result
            );

            return result;
        }
コード例 #7
0
        private static Object GetValue(PropertyAccessor property, Object target)
        {
            var value = property.GetValue(target);

            if (value == null)
            {
                Logger.Debug(
                    "Property {PropertyName} is null, skipping.",
                    property.Name
                );
            }

            return value;
        }
コード例 #8
0
        private static IResolveBuilder GetResolveBuilder(PropertyAccessor property, Object value)
        {
            var resolveBuilder = value as IResolveBuilder;
            if (resolveBuilder == null)
            {
                Logger.Debug(
                    "Property {PropertyName} value {$Value} is not an IResolveBuilder, skipping.",
                    property.Name,
                    value
                );
            }

            return resolveBuilder;
        }
コード例 #9
0
        private static Boolean HasNonUniqueParameterSetNames(
            PropertyAccessor property,
            IEnumerable<ParameterAttribute> attributes
        )
        {
            var nonUniqueParameterSetNames = attributes
                .GroupBy(p => p.ParameterSetName, ParameterSet.NameComparer)
                .Where(set => set.Count() > 1)
                .Select(set => set.Key);

            if (nonUniqueParameterSetNames.Any())
            {
                throw Logger.Fatal.ObjectMetadata(
                    SR.HarshProvisionerMetadata_MoreParametersWithSameSet,
                    property.DeclaringType,
                    property.Name,
                    String.Join(
                        ", ",
                        nonUniqueParameterSetNames.Select(
                            set => '"' + set + '"'
                        )
                    )
                );
            }

            return false;
        }
コード例 #10
0
        private static Boolean IsBothCommonParameterAndInParameterSet(
            PropertyAccessor property,
            IEnumerable<ParameterAttribute> attributes
        )
        {
            if (attributes.Any(a => a.ParameterSetName == null))
            {
                if (attributes.Count() > 1)
                {
                    throw Logger.Fatal.ObjectMetadata(
                        SR.HarshProvisionerMetadata_ParameterBothCommonAndInSet,
                        property.DeclaringType,
                        property.Name
                    );
                }
            }

            return false;
        }
コード例 #11
0
        private Boolean IsMandatoryAndUnsupportedByDefaultValuePolicy(
            PropertyAccessor property,
            IEnumerable<ParameterAttribute> attributes
        )
        {
            if (!DefaultValuePolicy.SupportsType(property.PropertyTypeInfo) &&
                attributes.Any(a => a.Mandatory))
            {
                throw Logger.Fatal.ObjectMetadata(
                    SR.HarshProvisionerMetadata_MandatoryTypeNotSupportedByDefaultValuePolicy,
                    property.DeclaringType,
                    property.Name,
                    property.PropertyType,
                    DefaultValuePolicy.GetType()
                );
            }

            return false;
        }
コード例 #12
0
 public void SetValue(ITrackValueSource target, Object value, PropertyValueSource source)
 => PropertyAccessor.SetValue(target, value, source);
コード例 #13
0
 public void SetValue(Object target, Object value)
 => PropertyAccessor.SetValue(target, value);
コード例 #14
0
 public PropertyValueSource GetValueSource(ITrackValueSource target)
 => PropertyAccessor.GetValueSource(target);
コード例 #15
0
 public Object GetValue(Object target)
 => PropertyAccessor.GetValue(target);
コード例 #16
0
 public override String ToString()
 => ParameterSetName == null?
 PropertyAccessor.ToString() :
     Invariant($"{PropertyAccessor} ParameterSetName={ParameterSetName}");