Пример #1
0
        internal static FunctionArgumentSignature Read(ParameterInfo parameterInfo)
        {
            Type     parameterType = parameterInfo.ParameterType;
            DataType dataType      = DataTypes.GetDataType(parameterType.IsByRef ? parameterType.GetElementType() : parameterType);

            if (dataType == DataType.None)
            {
                return(null);
            }

            return(new FunctionArgumentSignature(parameterInfo.Name, dataType, parameterType.IsByRef));
        }
Пример #2
0
        internal static FunctionSignature Read(MethodInfo method)
        {
            // check whether the method has a FunctionAttribute
            FunctionAttribute attribute = ReflectionUtilities.GetFirstAttribute <FunctionAttribute>(method, false);

            if (attribute == null)
            {
                return(null);
            }

            // get the result type of the function
            DataType resultType;
            Type     returnType = method.ReturnType;

            if (returnType == typeof(void))
            {
                resultType = DataType.None;
            }
            else
            {
                resultType = DataTypes.GetDataType(returnType);
                if (resultType == DataType.None)
                {
                    return(null);
                }
            }

            // get the function arguments
            ParameterInfo[] parameterInfos             = method.GetParameters();
            List <FunctionArgumentSignature> arguments = new List <FunctionArgumentSignature>(parameterInfos.Length);

            foreach (ParameterInfo parameterInfo in parameterInfos)
            {
                FunctionArgumentSignature argument = FunctionArgumentSignature.Read(parameterInfo);
                if (argument != null)
                {
                    arguments.Add(argument);
                }
                else
                {
                    return(null);
                }
            }

            return(new FunctionSignature(method, attribute.Name, resultType, new ReadOnlyCollection <FunctionArgumentSignature>(arguments)));
        }