コード例 #1
0
        public static ArgumentResult ParseArgumentTemplate(string template)
        {
            var result = new ArgumentResult();

            foreach (var token in TemplateTokenizer.Tokenize(template))
            {
                if (token.TokenKind == TemplateToken.Kind.ShortName ||
                    token.TokenKind == TemplateToken.Kind.LongName)
                {
                    throw TemplateException.ArgumentCannotContainOptions(template, token);
                }

                if (token.TokenKind == TemplateToken.Kind.OptionalValue ||
                    token.TokenKind == TemplateToken.Kind.RequiredValue)
                {
                    if (!string.IsNullOrWhiteSpace(result.Value))
                    {
                        throw TemplateException.MultipleValuesAreNotSupported(template, token);
                    }
                    if (string.IsNullOrWhiteSpace(token.Value))
                    {
                        throw TemplateException.ValuesMustHaveName(template, token);
                    }

                    result.Value    = token.Value;
                    result.Required = token.TokenKind == TemplateToken.Kind.RequiredValue;
                }
            }
            return(result);
        }