private static void LoadFunction(FunctionAttribute attribute, MethodInfo method)
        {
            ParameterInfo [] parameters = method.GetParameters();

            FunctionCache cache;

            cache.ArgumentCount = parameters == null ? 0 : parameters.Length;
            cache.Name          = attribute.Name;
            cache.Method        = method;
            cache.RawSymbols    = method.ReturnType == typeof(Symbol);

            if (parameters != null)
            {
                if (parameters.Length == 1 && parameters[0].ParameterType.IsArray &&
                    parameters[0].ParameterType.HasElementType &&
                    parameters[0].ParameterType.GetElementType() == method.ReturnType)
                {
                    cache.ArgumentCount = -1;
                }
                else
                {
                    foreach (ParameterInfo parameter in parameters)
                    {
                        if (parameter.ParameterType != method.ReturnType)
                        {
                            throw new ArgumentException(String.Format(
                                                            "'{0}': return and parameter types must be the same",
                                                            attribute.Name));
                        }
                    }
                }
            }

            cached_functions.Add(cache.Name, cache);
        }
        private static void LoadFunctionCache()
        {
            cached_functions = new Dictionary <string, FunctionCache>();

            foreach (Assembly assembly in assemblies)
            {
                foreach (Type type in assembly.GetTypes())
                {
                    foreach (MethodInfo method in type.GetMethods())
                    {
                        foreach (Attribute attr in method.GetCustomAttributes(typeof(FunctionAttribute), true))
                        {
                            FunctionAttribute attribute = attr as FunctionAttribute;
                            if (attribute == null)
                            {
                                continue;
                            }

                            LoadFunction(attribute, method);
                        }
                    }
                }
            }
        }
Beispiel #3
0
        private static void LoadFunction(FunctionAttribute attribute, MethodInfo method)
        {
            ParameterInfo [] parameters = method.GetParameters();

            FunctionCache cache;
            cache.ArgumentCount = parameters == null ? 0 : parameters.Length;
            cache.Name = attribute.Name;
            cache.Method = method;
            cache.RawSymbols = method.ReturnType == typeof(Symbol);

            if(parameters != null) {
                if(parameters.Length == 1 && parameters[0].ParameterType.IsArray &&
                    parameters[0].ParameterType.HasElementType &&
                    parameters[0].ParameterType.GetElementType() == method.ReturnType) {
                    cache.ArgumentCount = -1;
                } else {
                    foreach(ParameterInfo parameter in parameters) {
                        if(parameter.ParameterType != method.ReturnType) {
                            throw new ArgumentException(String.Format(
                                "'{0}': return and parameter types must be the same",
                                attribute.Name));
                        }
                    }
                }
            }

            cached_functions.Add(cache.Name, cache);
        }