private SwitchRecord CreateSwitchRecord(object obj, MemberInfo member, CommandLineSwitchAttribute switchAttribute) { SwitchRecord rec; if (member is PropertyInfo) { PropertyInfo pi = (PropertyInfo)member; rec = new SwitchRecord(switchAttribute.Name, switchAttribute.Description, pi.PropertyType); // Map in the Get/Set methods. rec.SetMethod = pi.GetSetMethod(); rec.GetMethod = pi.GetGetMethod(); rec.PropertyOwner = obj; } else { throw new NotImplementedException(member.GetType().FullName); } foreach (CommandLineAliasAttribute aliasAttrib in member.GetCustomAttributes(typeof(CommandLineAliasAttribute), false)) { rec.AddAlias(aliasAttrib.Alias); } return(rec); }
/// <summary> /// Adds the switch. /// </summary> /// <param name="name">The name.</param> /// <param name="description">The description.</param> public SwitchRecord AddSwitch(string name, string description) { SwitchRecord result = new SwitchRecord(name, description); switches.Add(name, result); return(result); }
/// <summary> /// Adds the switch. /// </summary> /// <param name="names">The names.</param> /// <param name="description">The description.</param> public void AddSwitch(string[] names, string description) { SwitchRecord rec = new SwitchRecord(names[0], description); for (int s = 1; s < names.Length; s++) { rec.AddAlias(names[s]); } switches.Add(names[0], rec); }
private void ProcessSwitch(SwitchRecord switchRecord) { MatchCollection matchCollection = switchRecord.Regex.Matches(m_workingString); foreach (Match match in matchCollection) { string value = null; if (match.Groups != null && match.Groups["value"] != null) { value = match.Groups["value"].Value; } if (switchRecord.Type == typeof(bool)) { bool state = true; // The value string may indicate what value we want. if (match.Groups != null && match.Groups["value"] != null) { switch (value) { case "+": state = true; break; case "-": state = false; break; case "": if (switchRecord.ReadValue != null) { state = !(bool)switchRecord.ReadValue; } break; default: break; } } switchRecord.Notify(state); break; } else if (switchRecord.Type == typeof(string)) { switchRecord.Notify(value); } else if (switchRecord.Type == typeof(int)) { switchRecord.Notify(int.Parse(value)); } else if (switchRecord.Type.IsEnum) { switchRecord.Notify(Enum.Parse(switchRecord.Type, value, true)); } } m_workingString = switchRecord.Regex.Replace(m_workingString, " "); }
/// <summary> /// Adds the switch. /// </summary> /// <param name="switchRecord">The switch record.</param> public void AddSwitch(SwitchRecord switchRecord) { switches.Add(switchRecord.Name, switchRecord); }