コード例 #1
0
 private void QuoteIfNeeded(ToolArgNode node)
 {
     if (node.Value == null || node.ValueQuotes != null)
     {
         return;
     }
     if (!node.Value.Contains(" "))
     {
         return;
     }
     node.ValueQuotes = "\"";
 }
コード例 #2
0
 void SetValue(ToolArgNode node, InstanceProperty pe)
 {
     if (node.Value != null)
     {
         if (pe.Property.PropertyType.Implements <IList>())
         {
             if (pe.Value == null)
             {
                 pe.Value = Activator.CreateInstance(pe.Property.PropertyType);
             }
             ((IList)pe.Value).Add(node.Value);
         }
         else
         {
             pe.Value = node.Value;
         }
     }
     else
     {
         pe.Value = true;
     }
 }
コード例 #3
0
 void AddNode(ToolArgNode node)
 {
     QuoteIfNeeded(node);
     Nodes.Add(node);
 }
コード例 #4
0
ファイル: ToolArgsParser.cs プロジェクト: arakis/corex
 public IEnumerable <ToolArgNode> Parse(string[] args)
 {
     foreach (var arg in args)
     {
         var arg2 = arg;
         if (arg2.IsNullOrEmpty())
         {
             continue;
         }
         var node        = new ToolArgNode();
         var switchChars = "/-";
         if (arg.StartsWith("@"))
         {
             var filename = arg.Substring(1);
             filename = TrimQuotesIfNeeded(filename);
             var argsFromFile = File.ReadAllText(filename);
             var tokens       = Parse(argsFromFile);
             foreach (var token in tokens)
             {
                 yield return(token);
             }
             continue;
         }
         if (arg2.StartsWithAnyChar(switchChars))
         {
             node.Switch = arg.TakeWhile(t => switchChars.Contains(t)).StringConcat();
             arg2        = arg2.Substring(node.Switch.Length);
         }
         if (IsQuoted(arg2))
         {
             node.ValueQuotes = arg2[0].ToString();
             node.Value       = arg2.SubstringBetween(1, arg2.Length - 1);
         }
         else
         {
             var sepChars = ":=";
             var sepIndex = arg2.IndexOfAnyChar(sepChars);
             if (sepIndex >= 0)
             {
                 node.Name      = arg2.SubstringBetween(0, sepIndex);
                 node.Seperator = arg2[sepIndex].ToString();
                 node.Value     = arg2.Substring(sepIndex + 1);
             }
             else
             {
                 if (node.Switch != null)
                 {
                     node.Name = arg2;
                 }
                 else
                 {
                     node.Value = arg2;
                 }
             }
             if (node.Value != null && IsQuoted(node.Value))
             {
                 node.ValueQuotes = node.Value[0].ToString();
                 node.Value       = node.Value.SubstringBetween(1, node.Value.Length - 1);
             }
         }
         yield return(node);
     }
 }