示例#1
0
        private static List <SwitchDef> GetSwitchDefinitions(Type type)
        {
            List <SwitchDef> switches = new List <SwitchDef>();

            PropertyInfo[] propertiesList = type.GetProperties();

            foreach (var property in propertiesList)
            {
                Switch   switchAttribute   = GetAttributes <Switch>(property).FirstOrDefault();
                Synopsis synopsisAttribute = GetAttributes <Synopsis>(property).FirstOrDefault();

                if (switchAttribute != null)
                {
                    SwitchDef newSwitch = new SwitchDef();
                    newSwitch.PropertyInfo = property;
                    newSwitch.Name         = switchAttribute.Name ?? property.Name;
                    newSwitch.AddAliases(GetAttributes <Alias>(property).Select(a => a.Value));
                    newSwitch.Synopsis = synopsisAttribute == null ? null : synopsisAttribute.Value;

                    switches.Add(newSwitch);
                }
            }

            return(switches);
        }
示例#2
0
        private void ResolveSwitch(InputNode node)
        {
            // get switch definition = add resolution error and exit if not found

            SwitchDef def = GetSwitchDefinition(node.Value);

            if (def == null) // switch is not defined in current definition
            {
                Nodes.Add(new CommandResolverNode()
                {
                    Type            = CRNodeType.Switch,
                    IsComplete      = false,
                    InputNode       = node,
                    ResolutionError = string.Format("Switch '{0}' is undefined", node.Value)
                });
            }
            else if (Nodes.Exists(n => n.Switch == def)) // build resolver node if not already defined
            {
                Nodes.Add(new CommandResolverNode()
                {
                    Type            = CRNodeType.Switch,
                    IsComplete      = false,
                    InputNode       = node,
                    ResolutionError = string.Format("Switch '{0}' is defined more than once", node.Value)
                });
            }
            else // resolve node
            {
                Nodes.Add(new CommandResolverNode()
                {
                    Type       = CRNodeType.Switch,
                    IsComplete = true,
                    InputNode  = node,
                    Switch     = def
                });
            }
        }