// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= public CmdLineParameter(PropertyInfo info, CmdLineArgAttribute attribute, CmdLineConfig config) { Field = null; Property = info; Config = config ?? throw new ArgumentNullException(nameof(config)); Name = attribute != null && attribute.ArgName != null ? attribute.ArgName : info.Name; Type = info.PropertyType; Attribute = attribute; if (attribute != null && attribute.Default != null) { HasDefaultValue = true; DefaultValue = attribute.Default; } else if (info.GetGetMethod().IsStatic) { DefaultValue = info.GetValue(null, null); HasDefaultValue = DefaultValue != null; } else { // pi.GetValue() for non-static requires object HasDefaultValue = false; DefaultValue = null; } if (HasDefaultValue && DefaultValue != null && !DefaultValue.GetType().IsEquivalentTo(Type)) { throw new CmdLineException("CmdLine error: invalid default value type for parameter " + Name); } }
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= public CmdLineParameter(ParameterInfo info, CmdLineArgAttribute attribute, CmdLineConfig config) { Field = null; Property = null; Config = config ?? throw new ArgumentNullException(nameof(config)); Name = attribute != null && attribute.ArgName != null ? attribute.ArgName : info.Name; Type = info.ParameterType; Attribute = attribute; if (info.HasDefaultValue) { HasDefaultValue = info.HasDefaultValue; DefaultValue = info.DefaultValue; } else if (attribute != null && attribute.Default != null) { HasDefaultValue = true; DefaultValue = attribute.Default; } else { HasDefaultValue = false; DefaultValue = null; } if (HasDefaultValue && DefaultValue != null && !DefaultValue.GetType().IsEquivalentTo(Type)) { throw new CmdLineException("CmdLine error: invalid default value type for parameter " + Name); } }
public FieldDefinition(FieldInfo field, CmdLineArgAttribute attribute) { Field = field; Attribute = attribute; }
public PropertyDefinition(PropertyInfo property, CmdLineArgAttribute attribute) { Property = property; Attribute = attribute; }