/// <summary> /// Creates a simple CSDL string for a method. /// </summary> public static CsdlSyntax CreateBasicSyntaxForMethod(MethodInfo methodInfo, bool rightToLeftParsing, bool perfectMatchOnly) { if (methodInfo == null) { throw new ArgumentNullException(nameof(methodInfo)); } var csdlTokenList = new List <CsdlToken>(); foreach (var parameter in methodInfo.GetParameters()) { var tokenTypeType = TokenTypeDictionary .FirstOrDefault(v => TypeUtil.GetGenericTokenTypeParameterType(v.Value) == parameter.ParameterType); if (tokenTypeType.Key != null) { var csdlToken = new CsdlToken(parameter.Name, tokenTypeType.Key, TypeUtil.IsNullable(parameter.ParameterType), false, null); csdlTokenList.Add(csdlToken); } else if (parameter.ParameterType != typeof(IRequestContext) && parameter.ParameterType != typeof(Expression)) { throw new ArgumentException( $"There's no registered token type for type '{parameter.ParameterType}'"); } } var csdlSyntax = new CsdlSyntax(rightToLeftParsing, perfectMatchOnly, csdlTokenList.ToArray()); return(csdlSyntax); }
/// <summary> /// Parses a CSDL string into a instance of <see cref="Syntax" />. /// </summary> /// <param name="syntaxPattern">The syntax pattern.</param> /// <param name="culture">The syntax culture.</param> /// <returns></returns> public static Syntax Parse(string syntaxPattern, CultureInfo culture) { var syntax = new CsdlSyntax(syntaxPattern); return(syntax.GetSyntax(TokenTypeDictionary, culture)); }