public PropertyArgumentDef( PropertyInfo propertyInfo, CommandNodeType commandNodeType, AppConfig appConfig, object modelInstance) { if (modelInstance == null) { throw new ArgumentNullException(nameof(modelInstance)); } _propertyInfo = propertyInfo ?? throw new ArgumentNullException(nameof(propertyInfo)); CommandNodeType = commandNodeType; Name = propertyInfo.BuildName(commandNodeType, appConfig); DefaultValue = propertyInfo.GetValue(modelInstance); ValueProxy = new ValueProxy( () => _propertyInfo.GetValue(modelInstance), value => _propertyInfo.SetValue(modelInstance, value) ); // Enhancement: AppSetting.StrictDefaults: show any default values that will be used. // If a value type doesn't have a default, it would be defined as a nullable type. // Keeping this behavior for legacy support. if (DefaultValue.IsDefaultFor(propertyInfo.PropertyType)) { DefaultValue = DBNull.Value; } HasDefaultValue = DefaultValue != DBNull.Value; }
public PropertyArgumentDef( PropertyInfo propertyInfo, CommandNodeType commandNodeType, AppConfig appConfig, object modelInstance) { if (modelInstance == null) { throw new ArgumentNullException(nameof(modelInstance)); } _propertyInfo = propertyInfo ?? throw new ArgumentNullException(nameof(propertyInfo)); CommandNodeType = commandNodeType; Name = propertyInfo.BuildName(commandNodeType, appConfig); IsOptional = propertyInfo.IsNullableProperty(); BooleanMode = this.GetBooleanMode(appConfig.AppSettings.Arguments.BooleanMode); Split = this.GetSplitChar(); ValueProxy = new ValueProxy( () => _propertyInfo.GetValue(modelInstance), value => _propertyInfo.SetValue(modelInstance, value) ); DefaultValue = propertyInfo.GetValue(modelInstance); HasDefaultValue = propertyInfo.PropertyType.IsClass ? !DefaultValue.IsNullValue() : !DefaultValue?.IsDefaultFor(propertyInfo.PropertyType) ?? false; Arity = ArgumentArity.Default(this); }
public ParameterArgumentDef( ParameterInfo parameterInfo, CommandNodeType commandNodeType, AppConfig appConfig, object?[] parameterValues) { if (parameterValues == null) { throw new ArgumentNullException(nameof(parameterValues)); } _parameterInfo = parameterInfo ?? throw new ArgumentNullException(nameof(parameterInfo)); CommandNodeType = commandNodeType; Name = parameterInfo.BuildName(commandNodeType, appConfig); IsOptional = _parameterInfo.IsOptional || _parameterInfo.IsNullableParameter(); BooleanMode = this.GetBooleanMode(appConfig.AppSettings.Arguments.BooleanMode); Split = this.GetSplitChar(); ValueProxy = new ValueProxy( () => parameterValues[parameterInfo.Position], value => parameterValues[parameterInfo.Position] = value ); Arity = ArgumentArity.Default(this); }
public CommandInfo(string?name, int?redirectId, CommandNodeType nodeType, int[] children, bool isExecutable, IArgumentParser?parser) { Name = name; RedirectId = redirectId; NodeType = nodeType; Children = children; IsExecutable = isExecutable; Parser = parser; }
internal static string BuildName(this ParameterInfo parameterInfo, CommandNodeType commandNodeType, AppConfig appConfig) { if (parameterInfo.Name is null) { throw new InvalidConfigurationException( $"{nameof(parameterInfo)}.{nameof(parameterInfo.Name)} cannot be null. host:{parameterInfo.Member} position:{parameterInfo.Position}"); } return(BuildName(parameterInfo, parameterInfo.Name, commandNodeType, appConfig)); }
public ParameterArgumentDef( ParameterInfo parameterInfo, CommandNodeType commandNodeType, AppConfig appConfig, object[] parameterValues) { if (parameterValues == null) { throw new ArgumentNullException(nameof(parameterValues)); } _parameterInfo = parameterInfo ?? throw new ArgumentNullException(nameof(parameterInfo)); CommandNodeType = commandNodeType; Name = parameterInfo.BuildName(commandNodeType, appConfig); ValueProxy = new ValueProxy( () => parameterValues[parameterInfo.Position], value => parameterValues[parameterInfo.Position] = value ); }
public PropertyData(PropertyInfo propertyInfo, int propertyIndex, PropertyData?parentProperty, CommandNodeType commandNode) { _parentProperty = parentProperty; PropertyInfo = propertyInfo; PropertyIndex = propertyIndex; IsArgModel = propertyInfo.PropertyType.InheritsFrom <IArgumentModel>(); LineNumber = propertyInfo.GetCustomAttribute <OperandAttribute>()?.CallerLineNumber ?? propertyInfo.GetCustomAttribute <OptionAttribute>()?.CallerLineNumber ?? propertyInfo.GetCustomAttribute <OrderByPositionInClassAttribute>()?.CallerLineNumber; var isOperand = !IsArgModel && commandNode == CommandNodeType.Operand; if (isOperand) { if (!LineNumber.HasValue) { throw new InvalidConfigurationException("Operand property must be attributed with " + $"{nameof(OperandAttribute)} or {nameof(OrderByPositionInClassAttribute)} to guarantee consistent order. " + $"Property: {propertyInfo.DeclaringType?.FullName}.{propertyInfo.Name}"); } var parentsWithoutLineNumber = ParentsWithoutLineNumber().ToList(); if (parentsWithoutLineNumber.Any()) { var props = parentsWithoutLineNumber .Select(p => p.PropertyInfo) .Select(p => $" {p.DeclaringType?.FullName}.{p.Name}") .ToCsv(Environment.NewLine); throw new InvalidConfigurationException("Operand property must be attributed with " + $"{nameof(OperandAttribute)} or {nameof(OrderByPositionInClassAttribute)} to guarantee consistent order. " + $"Properties:{Environment.NewLine}{props}"); } } }
private static string BuildName(ICustomAttributeProvider attributes, string memberName, CommandNodeType commandNodeType, AppConfig appConfig, string?overrideName = null) { overrideName ??= attributes.GetCustomAttributes(true).OfType <INameAndDescription>().FirstOrDefault()?.Name; return(appConfig.NameTransformation(attributes, memberName, overrideName, commandNodeType)); }
internal static string BuildName(this MemberInfo memberInfo, CommandNodeType commandNodeType, AppConfig appConfig, string?overrideName = null) { return(BuildName(memberInfo, memberInfo.Name, commandNodeType, appConfig, overrideName)); }
internal static string BuildName(this MemberInfo memberInfo, CommandNodeType commandNodeType, AppConfig appConfig) { return(BuildName(memberInfo, memberInfo.Name, commandNodeType, appConfig)); }
internal static string BuildName(this ParameterInfo parameterInfo, CommandNodeType commandNodeType, AppConfig appConfig) { return(BuildName(parameterInfo, parameterInfo.Name, commandNodeType, appConfig)); }