コード例 #1
0
ファイル: ReflectionTools.cs プロジェクト: tmteam/Gin
        /// <summary>
        /// Searching for the property value in the args list
        /// </summary>
        /// <returns>value, if value have founded, null false otherwise</returns>
        static object SearchExactAndGetValue(List <string> args, ArgumentDescription property, IEnumerable <ArgumentDescription> otherProperties, Type type)
        {
            var propertyName = property.Attribute.ShortAlias.ToLower();

            for (int i = 0; i < args.Count; i++)
            {
                if (propertyName == ParseTools.NormalizeCommandArgName(args[i]))
                {
                    //match!
                    var propertyType = ReflectionTools.GetNonNullType(property.Property.PropertyType);
                    var hasMore      = (i < args.Count - 1);
                    if (propertyType == typeof(bool))    //It can be flag!
                    {
                        if (!hasMore || otherProperties.Any(p => p.Attribute.ShortAlias.ToLower() == args[i + 1]))
                        {
                            args.RemoveAt(i);
                            return(true);   //it means flag value
                        }
                        else
                        {
                            var value = ParseTools.Convert(args[i + 1], propertyType, property.Attribute.ShortAlias);
                            args.RemoveAt(i);     //extract the name and the value from the list
                            args.RemoveAt(i);
                            return(value);
                        }
                    }
                    else
                    {
                        if (!hasMore)
                        {
                            throw new InvalidArgumentException(type, "", property.Attribute.ShortAlias);
                        }
                        var nonBoolValue = ParseTools.Convert(args[i + 1], propertyType, property.Attribute.ShortAlias);
                        args.RemoveAt(i);     //extract the name and the value from the list
                        args.RemoveAt(i);
                        return(nonBoolValue);
                    }
                }
            }
            return(null);
        }
コード例 #2
0
 private void fillArgDescription(StringBuilder msg, ArgumentDescription arg)
 {
     msg.AppendLine("    -" + arg.Attribute.ShortAlias + ",  (" + arg.Property.PropertyType.Name + ")   " + arg.Attribute.Description);
 }