Example #1
0
        /// <summary>
        /// Builds an array of signatures for math functions.
        /// </summary>
        /// <param name="methodName">The name of the method to call on the Math class.</param>
        /// <returns>The array of signatures for math functions.</returns>
        private static BuiltInFunctionSignature[] CreateMathFunctionSignatureArray(string methodName)
        {
            BuiltInFunctionSignature doubleSignature = BuiltInFunctionSignature.CreateFromStaticMethodCall(
                typeof(Math),
                methodName,
                EdmCoreModel.Instance.GetDouble(false),
                EdmCoreModel.Instance,
                EdmCoreModel.Instance.GetDouble(false));
            BuiltInFunctionSignature nullableDoubleSignature = BuiltInFunctionSignature.CreateFromStaticMethodCall(
                typeof(Math),
                methodName,
                EdmCoreModel.Instance.GetDouble(false),
                EdmCoreModel.Instance,
                EdmCoreModel.Instance.GetDouble(true));
            BuiltInFunctionSignature decimalSignature = BuiltInFunctionSignature.CreateFromStaticMethodCall(
                typeof(Math),
                methodName,
                EdmCoreModel.Instance.GetDecimal(false),
                EdmCoreModel.Instance,
                EdmCoreModel.Instance.GetDecimal(false));
            BuiltInFunctionSignature nullableDecimalSignature = BuiltInFunctionSignature.CreateFromStaticMethodCall(
                typeof(Math),
                methodName,
                EdmCoreModel.Instance.GetDecimal(false),
                EdmCoreModel.Instance,
                EdmCoreModel.Instance.GetDecimal(true));

            return(new BuiltInFunctionSignature[] { doubleSignature, decimalSignature, nullableDoubleSignature, nullableDecimalSignature });
        }
Example #2
0
        /// <summary>
        /// Creates all string functions.
        /// </summary>
        private static void CreateStringFunctions()
        {
            BuiltInFunctionSignature signature;

            BuiltInFunctionSignature[] signatures;

            // bool endswith(string, string)
            signature = BuiltInFunctionSignature.CreateFromInstanceMethodCall(
                "EndsWith",
                EdmCoreModel.Instance.GetBoolean(false),
                EdmCoreModel.Instance,
                EdmCoreModel.Instance.GetString(true),
                EdmCoreModel.Instance.GetString(true));
            builtInFunctions.Add("endswith", new BuiltInFunctionSignature[] { signature });

            // int indexof(string, string)
            signature = BuiltInFunctionSignature.CreateFromInstanceMethodCall(
                "IndexOf",
                EdmCoreModel.Instance.GetInt32(false),
                EdmCoreModel.Instance,
                EdmCoreModel.Instance.GetString(true),
                EdmCoreModel.Instance.GetString(true));
            builtInFunctions.Add("indexof", new BuiltInFunctionSignature[] { signature });

            // string replace(string, string, string)
            signature = BuiltInFunctionSignature.CreateFromInstanceMethodCall(
                "Replace",
                EdmCoreModel.Instance.GetString(true),
                EdmCoreModel.Instance,
                EdmCoreModel.Instance.GetString(true),
                EdmCoreModel.Instance.GetString(true),
                EdmCoreModel.Instance.GetString(true));
            builtInFunctions.Add("replace", new BuiltInFunctionSignature[] { signature });

            // bool startswith(string, string)
            signature = BuiltInFunctionSignature.CreateFromInstanceMethodCall(
                "StartsWith",
                EdmCoreModel.Instance.GetBoolean(false),
                EdmCoreModel.Instance,
                EdmCoreModel.Instance.GetString(true),
                EdmCoreModel.Instance.GetString(true));
            builtInFunctions.Add("startswith", new BuiltInFunctionSignature[] { signature });

            // string tolower(string)
            signature = BuiltInFunctionSignature.CreateFromInstanceMethodCall(
                "ToLower",
                EdmCoreModel.Instance.GetString(true),
                EdmCoreModel.Instance,
                EdmCoreModel.Instance.GetString(true));
            builtInFunctions.Add("tolower", new BuiltInFunctionSignature[] { signature });

            // string toupper(string)
            signature = BuiltInFunctionSignature.CreateFromInstanceMethodCall(
                "ToUpper",
                EdmCoreModel.Instance.GetString(true),
                EdmCoreModel.Instance,
                EdmCoreModel.Instance.GetString(true));
            builtInFunctions.Add("toupper", new BuiltInFunctionSignature[] { signature });

            // string trim(string)
            signature = BuiltInFunctionSignature.CreateFromInstanceMethodCall(
                "Trim",
                EdmCoreModel.Instance.GetString(true),
                EdmCoreModel.Instance,
                EdmCoreModel.Instance.GetString(true));
            builtInFunctions.Add("trim", new BuiltInFunctionSignature[] { signature });

            signatures = new BuiltInFunctionSignature[]
            {
                // string substring(string, int)
                BuiltInFunctionSignature.CreateFromInstanceMethodCall(
                    "Substring",
                    EdmCoreModel.Instance.GetString(true),
                    EdmCoreModel.Instance,
                    EdmCoreModel.Instance.GetString(true),
                    EdmCoreModel.Instance.GetInt32(false)),

                // string substring(string, int?)
                BuiltInFunctionSignature.CreateFromInstanceMethodCall(
                    "Substring",
                    EdmCoreModel.Instance.GetString(true),
                    EdmCoreModel.Instance,
                    EdmCoreModel.Instance.GetString(true),
                    EdmCoreModel.Instance.GetInt32(true)),

                // string substring(string, int, int)
                BuiltInFunctionSignature.CreateFromInstanceMethodCall(
                    "Substring",
                    EdmCoreModel.Instance.GetString(true),
                    EdmCoreModel.Instance,
                    EdmCoreModel.Instance.GetString(true),
                    EdmCoreModel.Instance.GetInt32(false),
                    EdmCoreModel.Instance.GetInt32(false)),

                // string substring(string, int?, int)
                BuiltInFunctionSignature.CreateFromInstanceMethodCall(
                    "Substring",
                    EdmCoreModel.Instance.GetString(true),
                    EdmCoreModel.Instance,
                    EdmCoreModel.Instance.GetString(true),
                    EdmCoreModel.Instance.GetInt32(true),
                    EdmCoreModel.Instance.GetInt32(false)),

                // string substring(string, int, int?)
                BuiltInFunctionSignature.CreateFromInstanceMethodCall(
                    "Substring",
                    EdmCoreModel.Instance.GetString(true),
                    EdmCoreModel.Instance,
                    EdmCoreModel.Instance.GetString(true),
                    EdmCoreModel.Instance.GetInt32(false),
                    EdmCoreModel.Instance.GetInt32(true)),

                // string substring(string, int?, int?)
                BuiltInFunctionSignature.CreateFromInstanceMethodCall(
                    "Substring",
                    EdmCoreModel.Instance.GetString(true),
                    EdmCoreModel.Instance,
                    EdmCoreModel.Instance.GetString(true),
                    EdmCoreModel.Instance.GetInt32(true),
                    EdmCoreModel.Instance.GetInt32(true))
            };
            builtInFunctions.Add("substring", signatures);

            // bool substringof(string, string)
            signature = new BuiltInFunctionSignature(
                BuildSubstringOfExpression,
                EdmCoreModel.Instance.GetBoolean(false),
                EdmCoreModel.Instance.GetString(true),
                EdmCoreModel.Instance.GetString(true));
            builtInFunctions.Add("substringof", new BuiltInFunctionSignature[] { signature });

            // string concat(string, string)
            signature = BuiltInFunctionSignature.CreateFromStaticMethodCall(
                typeof(string),
                "Concat",
                EdmCoreModel.Instance.GetString(true),
                EdmCoreModel.Instance,
                EdmCoreModel.Instance.GetString(true),
                EdmCoreModel.Instance.GetString(true));
            builtInFunctions.Add("concat", new BuiltInFunctionSignature[] { signature });

            // int length(string)
            signature = BuiltInFunctionSignature.CreateFromPropertyAccess(
                "Length",
                EdmCoreModel.Instance.GetInt32(false),
                EdmCoreModel.Instance,
                EdmCoreModel.Instance.GetString(true));
            builtInFunctions.Add("length", new BuiltInFunctionSignature[] { signature });
        }