public static void Main() { PropertyInfo property = typeof(CommandLineInfo).GetProperty("Help"); CommandLineSwitchAliasAttribute attribute = (CommandLineSwitchAliasAttribute) property.GetCustomAttributes( typeof(CommandLineSwitchAliasAttribute), false)[0]; if (attribute.Alias == "?") { Console.WriteLine("Help(?)"); } ; }
// ... public static bool TryParse( string[] args, object commandLine, out string errorMessage) { bool success = false; errorMessage = null; Dictionary <string, PropertyInfo> options = CommandLineSwitchAliasAttribute.GetSwitches( commandLine); foreach (string arg in args) { PropertyInfo property; string option; if (arg[0] == '/' || arg[0] == '-') { string[] optionParts = arg.Split( new char[] { ':' }, 2); option = optionParts[0].Remove(0, 1).ToLower(); if (options.TryGetValue(option, out property)) { success = SetOption( commandLine, property, optionParts, ref errorMessage); } else { success = false; errorMessage = $"Option '{option}' is not supported."; } } } return(success); }