GetAttribute() static private method

static private GetAttribute ( object target ) : ValueListAttribute
target object
return ValueListAttribute
Esempio n. 1
0
 public TargetWrapper(object target)
 {
     _target = target;
     _vla    = ValueListAttribute.GetAttribute(_target);
     if (IsValueListDefined)
     {
         _valueList = ValueListAttribute.GetReference(_target);
     }
 }
        private static bool ParseArgumentList(string[] args, object options)
        {
            bool               hadError  = false;
            OptionMap          optionMap = OptionInfo.CreateMap(options);
            IList <string>     valueList = ValueListAttribute.GetReference(options);
            ValueListAttribute vlAttr    = ValueListAttribute.GetAttribute(options);

            IStringEnumerator arguments = new StringEnumeratorEx(args);

            while (arguments.MoveNext())
            {
                string argument = arguments.Current;
                if (argument != null && argument.Length > 0)
                {
                    ArgumentParser parser = ArgumentParser.Create(argument);
                    if (parser != null)
                    {
                        ParserState result = parser.Parse(arguments, optionMap, options);
                        if ((result & ParserState.Failure) == ParserState.Failure)
                        {
                            hadError = true;
                            break;
                        }
                        if ((result & ParserState.MoveOnNextElement) == ParserState.MoveOnNextElement)
                        {
                            arguments.MoveNext();
                        }
                    }
                    else if (valueList != null)
                    {
                        if (vlAttr.MaximumElements < 0)
                        {
                            lock (valueListLock)
                            {
                                valueList.Add(argument);
                            }
                        }
                        else if (vlAttr.MaximumElements == 0)
                        {
                            hadError = true;
                            break;
                        }
                        else
                        {
                            if (vlAttr.MaximumElements > valueList.Count)
                            {
                                lock (valueListLock)
                                {
                                    valueList.Add(argument);
                                }
                            }
                            else
                            {
                                hadError = true;
                                break;
                            }
                        }
                    }
                }
            }

            hadError |= !optionMap.EnforceRules();
            return(!hadError);
        }