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(); }
public static Boolean IsResolveType(PropertyAccessor property) { if (property == null) { throw Logger.Fatal.ArgumentNull(nameof(property)); } return IsResolveType(property.PropertyTypeInfo); }
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); }
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); }
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(); }
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; }
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; }
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; }
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; }
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; }
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; }
public void SetValue(ITrackValueSource target, Object value, PropertyValueSource source) => PropertyAccessor.SetValue(target, value, source);
public void SetValue(Object target, Object value) => PropertyAccessor.SetValue(target, value);
public PropertyValueSource GetValueSource(ITrackValueSource target) => PropertyAccessor.GetValueSource(target);
public Object GetValue(Object target) => PropertyAccessor.GetValue(target);
public override String ToString() => ParameterSetName == null? PropertyAccessor.ToString() : Invariant($"{PropertyAccessor} ParameterSetName={ParameterSetName}");