Ejemplo n.º 1
0
        private SwitchRecord CreateSwitchRecord(object obj, MemberInfo member, CommandLineSwitchAttribute switchAttribute)
        {
            SwitchRecord rec;

            if (member is PropertyInfo)
            {
                var pi = (PropertyInfo)member;

                rec = new SwitchRecord(switchAttribute.Name,
                                       switchAttribute.Description,
                                       pi.PropertyType)
                {
                    SetMethod     = pi.GetSetMethod(),
                    GetMethod     = pi.GetGetMethod(),
                    PropertyOwner = obj
                };

                // Map in the Get/Set methods.
            }
            else
            {
                throw new NotImplementedException(member.GetType().FullName);
            }

            foreach (CommandLineAliasAttribute aliasAttrib in member.GetCustomAttributes(typeof(CommandLineAliasAttribute), false))
            {
                rec.AddAlias(aliasAttrib.Alias);
            }
            return(rec);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Adds the switch.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="description">The description.</param>
        public SwitchRecord AddSwitch(string name, string description)
        {
            var result = new SwitchRecord(name, description);

            _switches.Add(name, result);
            return(result);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Adds the switch.
        /// </summary>
        /// <param name="names">The names.</param>
        /// <param name="description">The description.</param>
        public void AddSwitch(string[] names, string description)
        {
            var rec = new SwitchRecord(names[0], description);

            for (var s = 1; s < names.Length; s++)
            {
                rec.AddAlias(names[s]);
            }
            _switches.Add(names[0], rec);
        }
Ejemplo n.º 4
0
        private void ProcessSwitch(SwitchRecord switchRecord)
        {
            MatchCollection matchCollection = switchRecord.Regex.Matches(_workingString);

            foreach (Match match in matchCollection)
            {
                string value = null;
                if (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 (value != null)
                    {
                        switch (value)
                        {
                        case "+":
                            state = true;
                            break;

                        case "-":
                            state = false;
                            break;

                        case "":
                            if (switchRecord.ReadValue != null)
                            {
                                state = !(bool)switchRecord.ReadValue;
                            }
                            break;
                        }
                    }
                    switchRecord.Notify(state);
                    break;
                }
                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));
                }
            }

            _workingString = switchRecord.Regex.Replace(_workingString, " ");
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Adds the switch.
 /// </summary>
 /// <param name="switchRecord">The switch record.</param>
 public void AddSwitch(SwitchRecord switchRecord)
 {
     _switches.Add(switchRecord.Name, switchRecord);
 }