Esempio n. 1
0
		public void AddSwitch(string name, string description)
		{
			if (m_switches == null)
				m_switches = new System.Collections.ArrayList();

			SwitchRecord rec = new SwitchRecord(name, description);
			m_switches.Add(rec);
		}
Esempio n. 2
0
		public void AddSwitch(string[] names, string description)
		{
			if (m_switches == null)
				m_switches = new System.Collections.ArrayList();
			SwitchRecord rec = new SwitchRecord(names[0], description);
			for (int s=1; s < names.Length; s++)
				rec.AddAlias(names[s]);
			m_switches.Add(rec);
		}
Esempio n. 3
0
 /// <summary>
 /// Constructor for the SwitchInfo class.  Note, in order to hide to the outside world
 /// information not necessary to know, the constructor takes a System.Object (aka
 /// object) as it's registering type.  If the type isn't of the correct type, an exception
 /// is thrown.
 /// </summary>
 /// <param name="rec">The SwitchRecord for which this class store information.</param>
 /// <exception cref="ArgumentException">Thrown if the rec parameter is not of
 /// the type SwitchRecord.</exception>
 public SwitchInfo(object rec)
 {
     if (rec is SwitchRecord)
     {
         _switch = rec as SwitchRecord;
     }
     else
     {
         throw new ArgumentException();
     }
 }
Esempio n. 4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="name"></param>
        /// <param name="description"></param>
        public void AddSwitch(string name, string description)
        {
            if (_switches == null)
            {
                _switches = new List <SwitchRecord>();
            }

            SwitchRecord rec = new SwitchRecord(name, description);

            _switches.Add(rec);
        }
Esempio n. 5
0
        public void AddSwitch(string name, bool required, string description)
        {
            if (m_switches == null)
            {
                m_switches = new ArrayList();
            }

            SwitchRecord rec = new SwitchRecord(name, required, description);

            m_switches.Add(rec);
        }
Esempio n. 6
0
        public void AddSwitch(string[] names, bool required, string description)
        {
            if (m_switches == null)
            {
                m_switches = new ArrayList();
            }
            SwitchRecord rec = new SwitchRecord(names[0], required, description);

            for (int s = 1; s < names.Length; s++)
            {
                rec.AddAlias(names[s]);
            }
            m_switches.Add(rec);
        }
Esempio n. 7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="names"></param>
        /// <param name="description"></param>
        public void AddSwitch(string[] names, string description)
        {
            if (_switches == null)
            {
                _switches = new List <SwitchRecord>();
            }
            SwitchRecord rec = new SwitchRecord(names[0], description);

            for (int s = 1; s < names.Length; s++)
            {
                rec.AddAlias(names[s]);
            }
            _switches.Add(rec);
        }
Esempio n. 8
0
        public Parser( string commandLine,
            object classForAutoAttributes)
        {
            m_commandLine = commandLine;

            Type type = classForAutoAttributes.GetType();
            System.Reflection.MemberInfo[] members = type.GetMembers();

            for(int i=0; i<members.Length; i++)
            {
                object[] attributes = members[i].GetCustomAttributes(false);
                if(attributes.Length > 0)
                {
                    SwitchRecord rec = null;

                    foreach ( Attribute attribute in attributes )
                    {
                        if ( attribute is CommandLineSwitchAttribute )
                        {
                            CommandLineSwitchAttribute switchAttrib =
                                (CommandLineSwitchAttribute) attribute;

                            // Get the property information.  We're only handling
                            // properties at the moment!
                            if ( members[i] is System.Reflection.PropertyInfo )
                            {
                                System.Reflection.PropertyInfo pi = (System.Reflection.PropertyInfo) members[i];

                                rec = new SwitchRecord( switchAttrib.Name,
                                                                switchAttrib.Description,
                                                                pi.PropertyType );

                                // Map in the Get/Set methods.
                                rec.SetMethod = pi.GetSetMethod();
                                rec.GetMethod = pi.GetGetMethod();
                                rec.PropertyOwner = classForAutoAttributes;

                                // Can only handle a single switch for each property
                                // (otherwise the parsing of aliases gets silly...)
                                break;
                            }
                        }
                    }

                    // See if any aliases are required.  We can only do this after
                    // a switch has been registered and the framework doesn't make
                    // any guarantees about the order of attributes, so we have to
                    // walk the collection a second time.
                    if ( rec != null )
                    {
                        foreach ( Attribute attribute in attributes )
                        {
                            if ( attribute is CommandLineAliasAttribute )
                            {
                                CommandLineAliasAttribute aliasAttrib =
                                    (CommandLineAliasAttribute) attribute;
                                rec.AddAlias( aliasAttrib.Alias );
                            }
                        }
                    }

                    // Assuming we have a switch record (that may or may not have
                    // aliases), add it to the collection of switches.
                    if ( rec != null )
                    {
                        if ( m_switches == null )
                            m_switches = new System.Collections.ArrayList();
                        m_switches.Add( rec );
                    }
                }
            }
        }
Esempio n. 9
0
 public void AddSwitch( string[] names, string description )
 {
     if ( m_switches == null )
         m_switches = new System.Collections.ArrayList();
     SwitchRecord rec = new SwitchRecord( names[0], description );
     for ( int s=1; s<names.Length; s++ )
         rec.AddAlias( names[s] );
     m_switches.Add( rec );
 }
Esempio n. 10
0
        public void AddSwitch( string name, string description )
        {
            if ( m_switches == null )
                m_switches = new System.Collections.ArrayList();

            SwitchRecord rec = new SwitchRecord( name, description );
            m_switches.Add( rec );
        }
Esempio n. 11
0
        public RMCommandParser(string commandLine,
                               object classForAutoAttributes)
        {
            m_commandLine = commandLine;

            Type type = classForAutoAttributes.GetType();

            System.Reflection.MemberInfo[] members = type.GetMembers();

            for (int i = 0; i < members.Length; i++)
            {
                object[] attributes = members[i].GetCustomAttributes(false);
                if (attributes.Length > 0)
                {
                    SwitchRecord rec = null;

                    foreach (Attribute attribute in attributes)
                    {
                        if (attribute is CommandLineSwitchAttribute)
                        {
                            CommandLineSwitchAttribute switchAttrib =
                                (CommandLineSwitchAttribute)attribute;

                            // Get the property information.  We're only handling
                            // properties at the moment!
                            if (members[i] is System.Reflection.PropertyInfo)
                            {
                                System.Reflection.PropertyInfo pi = (System.Reflection.PropertyInfo)members[i];

                                rec = new SwitchRecord(switchAttrib.Name,
                                                       switchAttrib.Description,
                                                       pi.PropertyType);

                                // Map in the Get/Set methods.
                                rec.SetMethod     = pi.GetSetMethod();
                                rec.GetMethod     = pi.GetGetMethod();
                                rec.PropertyOwner = classForAutoAttributes;

                                // Can only handle a single switch for each property
                                // (otherwise the parsing of aliases gets silly...)
                                break;
                            }
                        }
                    }

                    // See if any aliases are required.  We can only do this after
                    // a switch has been registered and the framework doesn't make
                    // any guarantees about the order of attributes, so we have to
                    // walk the collection a second time.
                    if (rec != null)
                    {
                        foreach (Attribute attribute in attributes)
                        {
                            if (attribute is CommandLineAliasAttribute)
                            {
                                CommandLineAliasAttribute aliasAttrib =
                                    (CommandLineAliasAttribute)attribute;
                                rec.AddAlias(aliasAttrib.Alias);
                            }
                        }
                    }

                    // Assuming we have a switch record (that may or may not have
                    // aliases), add it to the collection of switches.
                    if (rec != null)
                    {
                        if (m_switches == null)
                        {
                            m_switches = new System.Collections.ArrayList();
                        }
                        m_switches.Add(rec);
                    }
                }
            }
        }
Esempio n. 12
0
 /// <summary>
 /// Constructor for the SwitchInfo class.  Note, in order to hide to the outside world
 /// information not necessary to know, the constructor takes a System.Object (aka
 /// object) as it's registering type.  If the type isn't of the correct type, an exception
 /// is thrown.
 /// </summary>
 /// <param name="rec">The SwitchRecord for which this class store information.</param>
 /// <exception cref="ArgumentException">Thrown if the rec parameter is not of
 /// the type SwitchRecord.</exception>
 public SwitchInfo(object rec)
 {
     if (rec is SwitchRecord)
         _switch = rec as SwitchRecord;
     else
         throw new ArgumentException();
 }
Esempio n. 13
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="names"></param>
 /// <param name="description"></param>
 public void AddSwitch(string[] names, string description)
 {
     if (_switches == null)
         _switches = new List<SwitchRecord>();
     SwitchRecord rec = new SwitchRecord(names[0], description);
     for (int s = 1; s < names.Length; s++)
         rec.AddAlias(names[s]);
     _switches.Add(rec);
 }
Esempio n. 14
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="name"></param>
        /// <param name="description"></param>
        public void AddSwitch(string name, string description)
        {
            if (_switches == null)
                _switches = new List<SwitchRecord>();

            SwitchRecord rec = new SwitchRecord(name, description);
            _switches.Add(rec);
        }
        public CommandLineParser(string commandLine, object commandLineInfo)
        {
            _CommandLine = commandLine;

            Type type = commandLineInfo.GetType();

            PropertyInfo[] properties = type.GetProperties(
                BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance
                | BindingFlags.FlattenHierarchy);

            for (int i = 0; i < properties.Length; i++)
            {
                object[] attributes = properties[i].GetCustomAttributes(false);
                if (attributes.Length > 0)
                {
                    SwitchRecord rec = null;

                    foreach (Attribute attribute in attributes)
                    {
                        if (attribute is CommandLineOptionAttribute)
                        {
                            CommandLineOptionAttribute switchAttrib =
                                (CommandLineOptionAttribute)attribute;

                            System.Reflection.PropertyInfo property = properties[i];

                            rec = new SwitchRecord(switchAttrib.Name,
                                                   switchAttrib.Description,
                                                   property.PropertyType);

                            // Map in the Get/Set methods.
                            rec.SetMethod     = property.GetSetMethod();
                            rec.GetMethod     = property.GetGetMethod();
                            rec.PropertyOwner = commandLineInfo;

                            // Can only handle a single switch for each property
                            // (otherwise the parsing of aliases gets silly...)
                            break;
                        }
                    }

#if ALIAS
                    // See if any aliases are required.  We can only do this after
                    // a switch has been registered and the framework doesn't make
                    // any guarantees about the order of attributes, so we have to
                    // walk the collection a second time.
                    if (rec != null)
                    {
                        foreach (Attribute attribute in attributes)
                        {
                            if (attribute is CommandLineAliasAttribute)
                            {
                                CommandLineAliasAttribute aliasAttrib =
                                    (CommandLineAliasAttribute)attribute;
                                rec.AddAlias(aliasAttrib.Alias);
                            }
                        }
                    }
#endif


                    // Assuming we have a switch record (that may or may not have
                    // aliases), add it to the collection of switches.
                    if (rec != null)
                    {
                        if (_Switches == null)
                        {
                            _Switches = new System.Collections.ArrayList();
                        }
                        _Switches.Add(rec);
                    }
                }
            }
        }
Esempio n. 16
0
        public void Initialize(string commandLine, object classForAutoAttributes)
        {
            if (classForAutoAttributes == null)
            {
                throw new ArgumentNullException("classForAutoAttributes");
            }

            m_commandLine = commandLine;

            Type type = classForAutoAttributes.GetType();

            MemberInfo[] members = type.GetMembers();

            for (int i = 0; i < members.Length; i++)
            {
                object[] attributes = members[i].GetCustomAttributes(false);
                if (attributes.Length > 0)
                {
                    SwitchRecord rec = null;

                    foreach (Attribute attribute in attributes)
                    {
                        CommandLineSwitchAttribute switchAttrib = attribute as CommandLineSwitchAttribute;
                        if (switchAttrib != null)
                        {
                            // Get the property information.  We're only handling
                            // properties at the moment!
                            if (members[i] is PropertyInfo)
                            {
                                PropertyInfo pi = (PropertyInfo)members[i];

                                rec = new SwitchRecord(switchAttrib.Name, switchAttrib.Required,
                                                       switchAttrib.Description, pi.PropertyType);

                                // Map in the Get/Set methods.
                                rec.SetMethod     = pi.GetSetMethod();
                                rec.GetMethod     = pi.GetGetMethod();
                                rec.PropertyOwner = classForAutoAttributes;

                                // Can only handle a single switch for each property
                                // (otherwise the parsing of aliases gets silly...)
                                break;
                            }
                        }
                    }

                    // See if any aliases are required.  We can only do this after
                    // a switch has been registered and the framework doesn't make
                    // any guarantees about the order of attributes, so we have to
                    // walk the collection a second time.
                    if (rec != null)
                    {
                        foreach (Attribute attribute in attributes)
                        {
                            CommandLineAliasAttribute aliasAttrib = attribute as CommandLineAliasAttribute;
                            if (aliasAttrib != null)
                            {
                                rec.AddAlias(aliasAttrib.Alias);
                            }
                        }
                    }

                    // Assuming we have a switch record (that may or may not have
                    // aliases), add it to the collection of switches.
                    if (rec != null)
                    {
                        if (m_switches == null)
                        {
                            m_switches = new ArrayList();
                        }

                        // make sure a switch with the same name has not been inserted before
                        foreach (SwitchRecord switchRec in m_switches)
                        {
                            if (rec.Name == switchRec.Name)
                            {
                                throw new ArgumentException(string.Format("Switch '{0}' used ambiguously.", switchRec.Name), "classForAutoAttributes");
                            }
                            if (rec.Aliases != null)
                            {
                                foreach (string alias in rec.Aliases)
                                {
                                    if (switchRec.Aliases != null)
                                    {
                                        foreach (string otherAlias in switchRec.Aliases)
                                        {
                                            if (alias == otherAlias)
                                            {
                                                throw new ArgumentException(string.Format("Switch alias '{0}' used ambiguously (for switch '{1}' and '{2}'.", otherAlias, switchRec.Name, rec.Name), "classForAutoAttributes");
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        m_switches.Add(rec);
                    }
                }
            }
        }
Esempio n. 17
0
        public void AddSwitch(string name, bool required, string description)
        {
            if (m_switches == null)
                m_switches = new ArrayList();

            SwitchRecord rec = new SwitchRecord(name, required, description);
            m_switches.Add(rec);
        }
Esempio n. 18
0
        public void Initialize(string commandLine, object classForAutoAttributes)
        {
            if (classForAutoAttributes == null) throw new ArgumentNullException("classForAutoAttributes");

            m_commandLine = commandLine;

            Type type = classForAutoAttributes.GetType();
            MemberInfo[] members = type.GetMembers();

            for (int i = 0; i < members.Length; i++)
            {
                object[] attributes = members[i].GetCustomAttributes(false);
                if (attributes.Length > 0)
                {
                    SwitchRecord rec = null;

                    foreach (Attribute attribute in attributes)
                    {
                        CommandLineSwitchAttribute switchAttrib = attribute as CommandLineSwitchAttribute;
                        if (switchAttrib != null)
                        {
                            // Get the property information.  We're only handling
                            // properties at the moment!
                            if (members[i] is PropertyInfo)
                            {
                                PropertyInfo pi = (PropertyInfo)members[i];

                                rec = new SwitchRecord(switchAttrib.Name, switchAttrib.Required,
                                    switchAttrib.Description, pi.PropertyType);

                                // Map in the Get/Set methods.
                                rec.SetMethod = pi.GetSetMethod();
                                rec.GetMethod = pi.GetGetMethod();
                                rec.PropertyOwner = classForAutoAttributes;

                                // Can only handle a single switch for each property
                                // (otherwise the parsing of aliases gets silly...)
                                break;
                            }
                        }
                    }

                    // See if any aliases are required.  We can only do this after
                    // a switch has been registered and the framework doesn't make
                    // any guarantees about the order of attributes, so we have to
                    // walk the collection a second time.
                    if (rec != null)
                    {
                        foreach (Attribute attribute in attributes)
                        {
                            CommandLineAliasAttribute aliasAttrib = attribute as CommandLineAliasAttribute;
                            if (aliasAttrib != null)
                            {
                                rec.AddAlias(aliasAttrib.Alias);
                            }
                        }
                    }

                    // Assuming we have a switch record (that may or may not have
                    // aliases), add it to the collection of switches.
                    if (rec != null)
                    {
                        if (m_switches == null)
                            m_switches = new ArrayList();

                        // make sure a switch with the same name has not been inserted before
                        foreach (SwitchRecord switchRec in m_switches)
                        {
                            if (rec.Name == switchRec.Name)
                            {
                                throw new ArgumentException(string.Format("Switch '{0}' used ambiguously.", switchRec.Name), "classForAutoAttributes");
                            }
                            if (rec.Aliases != null)
                            {
                                foreach (string alias in rec.Aliases)
                                {
                                    if (switchRec.Aliases != null)
                                    {
                                        foreach (string otherAlias in switchRec.Aliases)
                                        {
                                            if (alias == otherAlias)
                                            {
                                                throw new ArgumentException(string.Format("Switch alias '{0}' used ambiguously (for switch '{1}' and '{2}'.", otherAlias, switchRec.Name, rec.Name), "classForAutoAttributes");
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        m_switches.Add(rec);
                    }
                }
            }
        }