Esempio n. 1
0
        /// <summary>
        /// Looks for .NET method
        /// </summary>
        /// <param name="generator">The IL generator.</param>
        /// <param name="callNode">The node which called the .NET static method</param>
        /// <returns>ILFunctionRef for called .NET static method.
        /// <c>null</c> - if there is no static method with this name exist in .NET framework</returns>
        public static ILFunctionRef LookForDotNetMethod(ILCodeGenerator generator, FunctionCall callNode)
        {
            string name  = callNode.Name;
            int    index = name.LastIndexOf('.');

            if (index == -1)
            {
                return(null);
            }
            string typeName   = name.Substring(0, index);
            string methodName = name.Substring(index + 1);

            System.Type type = System.Type.GetType(typeName);
            if (type == null)
            {
                type = System.Type.GetType("System." + typeName);
            }
            if (type == null)
            {
                return(null);
            }


            List <Type>         argTypes = new List <Type>();
            ExpressionGenerator g        = new ExpressionGenerator(generator);

            foreach (Expression arg in callNode)
            {
                argTypes.Add(ILTypeTranslator.Translate(g.Create(arg).Type));
            }

            MethodInfo method = type.GetMethod(methodName, argTypes.ToArray());

            if (method == null || !method.IsStatic)
            {
                return(null);
            }

            return(new ILFunctionRef(generator, method));
        }