示例#1
0
        public static CompiledKontrolFunction BindFunction(Type type, string methodName, string description,
                                                           params Type[] parameterTypes)
        {
            string     name       = BindingGenerator.ToSnakeCase(methodName);
            MethodInfo methodInfo = type.GetMethod(methodName, parameterTypes) ??
                                    throw new ArgumentException($"Method {methodName} not found in {type}");
            List <RealizedParameter> parameters = methodInfo.GetParameters().Select(p =>
                                                                                    new RealizedParameter(p.Name, BindingGenerator.MapNativeType(p.ParameterType),
                                                                                                          BoundDefaultValue.DefaultValueFor(p))).ToList();

            if (methodInfo.ReturnType.IsGenericType &&
                methodInfo.ReturnType.GetGenericTypeDefinition() == typeof(Future <>))
            {
                RealizedType returnType =
                    BindingGenerator.MapNativeType(methodInfo.ReturnType.GetGenericArguments()[0]);

                return(new CompiledKontrolFunction(name, description, true, parameters, returnType, methodInfo));
            }
            else
            {
                RealizedType returnType = BindingGenerator.MapNativeType(methodInfo.ReturnType);

                return(new CompiledKontrolFunction(name, description, false, parameters, returnType, methodInfo));
            }
        }
示例#2
0
        public static CompiledKontrolConstant BindConstant(Type type, string fieldName, string description)
        {
            string    name      = BindingGenerator.ToSnakeCase(fieldName).ToUpperInvariant();
            FieldInfo fieldInfo = type.GetField(fieldName);
            TO2Type   to2Type   = BindingGenerator.MapNativeType(fieldInfo.FieldType);

            return(new CompiledKontrolConstant(name, description, to2Type, fieldInfo));
        }