Ejemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="scope"></param>
        /// <param name="nameSpace"></param>
        /// <param name="parametersCount">filter functions by number of parameters</param>
        /// <param name="parametersNames"></param>
        /// <returns></returns>
        public static QsFunction[] FindFunctionByParameters(
            QsScope scope,
            string qsNamespace,
            string functionName,
            int parametersCount,
            params string[] parametersNames)
        {
            IEnumerable <KeyValuePair <string, object> > Items = null;

            if (!string.IsNullOrEmpty(qsNamespace))
            {
                var ns = QsNamespace.GetNamespace(scope, qsNamespace);
                Items = ns.GetItems();
            }
            else
            {
                Items = scope.GetItems();
            }

            var func_Pass1 = from item in Items
                             where item.Value is QsFunction
                             select(QsFunction) item.Value;

            var func_Pass2 = from func in func_Pass1
                             where func.ContainsParameters(parametersNames) && func.Parameters.Length == parametersCount
                             select func;

            var func_Pass3 = from fc in func_Pass2
                             where fc.FunctionName.Equals(functionName, StringComparison.OrdinalIgnoreCase)
                             select fc;


            return(func_Pass3.ToArray());
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Get the first declared function of this undecorated name.
        /// </summary>
        /// <param name="scope"></param>
        /// <param name="nameSpace"></param>
        /// <param name="functionName"></param>
        /// <returns></returns>
        public static QsFunction GetFirstDeclaredFunction(
            QsScope scope,
            string nameSpace,
            string functionName)
        {
            IEnumerable <KeyValuePair <string, object> > Items = null;

            if (!string.IsNullOrEmpty(nameSpace))
            {
                var ns = QsNamespace.GetNamespace(scope, nameSpace);
                Items = ns.GetItems();
            }
            else
            {
                Items = scope.GetItems();
            }

            var func_Pass1 = from item in Items
                             where item.Value is QsFunction
                             select(QsFunction) item.Value;

            var qf = from fun in func_Pass1
                     where fun.FunctionName.Equals(functionName, StringComparison.OrdinalIgnoreCase)
                     select fun;


            return(qf.ElementAtOrDefault(0));
        }