public ArgumentUsageInfo(PropertyInfo toAutoGen) : this() { Property = toAutoGen; Name = "-" + NameTranslators.CombineByPascalCase(toAutoGen.Name, "-").ToLower(); Aliases.Add("-" + Property.Name); if (Aliases.Count == 0) { Aliases.Add("-" + Name.ToLower()); } var argAliases = Property.HasAttr<ArgAliasAttribute>() ? Property.Attr<ArgAliasAttribute>().Aliases : null; if(argAliases != null) { Aliases.AddRange(argAliases.Select(x=> "-" + NameTranslators.CombineByPascalCase(x, "-"))); } Description = Property.HasAttr<ArgDescriptionAttribute>() ? Property.Attr<ArgDescriptionAttribute>().Description : ""; Group = Property.HasAttr<ArgDescriptionAttribute>() ? Property.Attr<ArgDescriptionAttribute>().Group : ""; if (Property.PropertyType.IsEnum) { foreach (var val in toAutoGen.PropertyType.GetFields().Where(v => v.IsSpecialName == false)) { var description = val.HasAttr<ArgDescriptionAttribute>() ? " - " + val.Attr<ArgDescriptionAttribute>().Description : ""; var valText = val.Name; PossibleValues.Add(valText + description); } } }
/// <summary> /// Generate a new info instance given a reflected property. /// </summary> /// <param name="toAutoGen">The property to use to seed the usage info</param> public ArgumentUsageInfo(CommandLineArgument toAutoGen) : this() { this.Argument = toAutoGen; Property = toAutoGen.Source as PropertyInfo; Ignore = false; IsAction = toAutoGen.DefaultAlias == Constants.ActionPropertyConventionName; DefaultValue = toAutoGen.DefaultValue; IsRequired = toAutoGen.IsRequired; Name = "-" + toAutoGen.DefaultAlias; if (Name.EndsWith(Constants.ActionArgConventionSuffix)) { Name = Name.Substring(0, Name.Length - Constants.ActionArgConventionSuffix.Length); } Aliases.AddRange(toAutoGen.Aliases.Skip(1).Select(a => "-" + a)); Type = toAutoGen.FriendlyTypeName; Position = toAutoGen.Position >= 0 ? new int?(toAutoGen.Position) : null; Description = toAutoGen.Description ?? ""; if (toAutoGen.ArgumentType.IsEnum) { foreach (var val in toAutoGen.ArgumentType.GetFields().Where(v => v.IsSpecialName == false)) { var description = val.HasAttr <ArgDescription>() ? " - " + val.Attr <ArgDescription>().Description : ""; var valText = val.Name; PossibleValues.Add(valText + description); } } }
public ReflectionCommand(CommandReflectionData refData) : base(refData.AllowedParameterTypes.Length) { this.refData = refData; //Setting the Data from the attributes SetName(refData.Attribute.Name); SetHelpMessage(refData.Attribute.HelpMessage); Aliases.AddRange(refData.Attribute.Aliases); }
/// <summary> /// Copy constructor /// </summary> /// <param name="viewModel">The viewmodel to copy.</param> public CharacterViewModel(CharacterViewModel viewModel) { Id = viewModel.Id; Name = viewModel.Name; Description = viewModel.Description; XPosition = viewModel.XPosition; YPosition = viewModel.YPosition; Aliases.AddRange(viewModel.Aliases); Authors.AddRange(viewModel.Authors); }
/// <summary> /// Initializes a new instance of the <see cref="CharacterViewModel"/> class. /// </summary> /// <param name="character">The <see cref="Character"/> for which to create this viewmodel.</param> /// <param name="getIdForModelFunc">A function returning the Id for the provided model.</param> public CharacterViewModel(RedYarn.Character character, Func <object, Guid> getIdForModelFunc = null) { if (getIdForModelFunc != null) { Id = getIdForModelFunc(character); } Name = character.Name; Description = character.Description; Aliases.AddRange(character.Aliases.Select(alias => new AliasViewModel(alias, getIdForModelFunc)).ToList()); }
/// <summary> /// Generate a new info instance given a reflected property. /// </summary> /// <param name="toAutoGen">The property to use to seed the usage info</param> public ArgumentUsageInfo(CommandLineArgument toAutoGen) : this() { this.Argument = toAutoGen; Property = toAutoGen.Source as PropertyInfo; Ignore = false; IsAction = toAutoGen.DefaultAlias == Constants.ActionPropertyConventionName; DefaultValue = toAutoGen.DefaultValue; IsRequired = toAutoGen.IsRequired; Name = "-" + toAutoGen.DefaultAlias; if (Name.EndsWith(Constants.ActionArgConventionSuffix)) { Name = Name.Substring(0, Name.Length - Constants.ActionArgConventionSuffix.Length); } Aliases.AddRange(toAutoGen.Aliases.Skip(1).Select(a => "-" + a)); if (Aliases.Count == 0) { //add shortcut alias Aliases.Add("-" + Name.ToLower()); } Type = toAutoGen.ArgumentType.Name; if (KnownTypeMappings.ContainsKey(Type)) { Type = KnownTypeMappings[Type]; } else { Type = Type.ToLower(); } Position = toAutoGen.Position >= 0 ? new int?(toAutoGen.Position) : null; Description = toAutoGen.Description ?? ""; Group = Property.HasAttr <ArgDescription>() ? Property.Attr <ArgDescription>().Group : ""; if (toAutoGen.ArgumentType.IsEnum) { foreach (var val in toAutoGen.ArgumentType.GetFields().Where(v => v.IsSpecialName == false)) { var description = val.HasAttr <ArgDescription>() ? " - " + val.Attr <ArgDescription>().Description : ""; var valText = val.Name; PossibleValues.Add(valText + description); } } }