예제 #1
0
        public static MethodName FromMethodInfo(System.Reflection.MethodInfo method)
        {
            if (method == null)
            {
                throw new ArgumentNullException(nameof(method));
            }

            if (method.IsGenericMethod && !method.IsGenericMethodDefinition)
            {
                return(new GenericInstanceMethodName(
                           FromMethodInfo(method.GetGenericMethodDefinition()),
                           method.GetGenericArguments().Select(TypeName.FromType).ToArray()
                           ));
            }

            var generics = DefaultMethodName.SetGenericMangle(0);

            if (method.IsGenericMethodDefinition)
            {
                generics = DefaultMethodName.SetGenericArguments(method.GetGenericArguments());
            }

            var result = new DefaultMethodName(
                TypeName.FromType(method.DeclaringType),
                method.Name,
                generics,
                DefaultMethodName.SetParameters(method.GetParameters()),
                DefaultMethodName.SetReturnType(TypeName.FromType(method.ReturnType))
                );

            return(result);
        }
예제 #2
0
        public FunctionAggregatorDeclaration <TKey, TComposite> MapServiceMethodToFunctionMethod(
            System.Reflection.MethodInfo serviceMethod,
            System.Reflection.MethodInfo functionMethod,
            Func <Object[], IEnumerable <TKey> > functionLookup,
            Func <Object[], Object[]> preArgTransformer,
            Action <Object[], Object[]> postArgProcessor,
            Func <Application, IEnumerable <TKey>, IEnumerable <KeyValuePair <TKey, Lazy <TComposite> > >, Object[], Tuple <TKey, TComposite, Boolean> > funcWhenDirectLookupFails
            //Func<TKey, TComposite, Object[], IEnumerable<Tuple<String, Object>>> additionalRolesFunc
            )
        {
            ArgumentValidator.ValidateNotNull("Service method", serviceMethod);
            ArgumentValidator.ValidateNotNull("Function method", functionMethod);
            ArgumentValidator.ValidateNotNull("Function lookup", functionLookup);

            var assemblyDeclaration = this._assemblyDeclaration;

            if (preArgTransformer == null)
            {
                preArgTransformer = NO_ARGS_TRANSFORM;
            }
            if (postArgProcessor == null)
            {
                postArgProcessor = NO_POST_ARG_TRANSFORMER_ACTION;
            }

            if (serviceMethod.IsGenericMethod && !serviceMethod.IsGenericMethodDefinition)
            {
                serviceMethod = serviceMethod.GetGenericMethodDefinition();
            }

            //         var keyType = typeof( TKey );
            //         var functionType = typeof( TComposite );

            // TODO check that method generic args match between service and function method
            assemblyDeclaration.WithMixins(typeof(FunctionServiceRegisterMixin <TKey, TComposite>));
            assemblyDeclaration
            .WithMixins(typeof(FunctionServiceMixin <TKey, TComposite>))
            .ApplyWith(new AppliesToFilterFromFunction((cMethod, fMethod) => serviceMethod.Equals(cMethod)));         // Add mixin for function method

            var info = this.GetInfo();

            info.FunctionMethods[serviceMethod]      = functionMethod;
            info.ArgsPreTransformers[serviceMethod]  = preArgTransformer;
            info.ArgsPostTransformers[serviceMethod] = postArgProcessor;
            info.LookupFuncs[serviceMethod]          = functionLookup;
            //if ( additionalRolesFunc != null )
            //{
            //   info.AdditionalRoles[serviceMethod] = additionalRolesFunc;
            //}
            if (funcWhenDirectLookupFails != null)
            {
                info.DirectLookupFailFuncs[serviceMethod] = funcWhenDirectLookupFails;
            }

            return(this);
        }
예제 #3
0
                    static System.Reflection.MethodInfo?MapMethod(System.Reflection.MethodInfo source)
                    {
                        var method = source.GetGenericMethodDefinition();

                        if (method == IncludeQueryableExtensions.IncludeMethodInfo)
                        {
                            return(EntityFrameworkMethodInfos.IncludeMethodInfo);
                        }

                        if (method == IncludeQueryableExtensions.StringIncludeMethodInfo)
                        {
                            return(EntityFrameworkMethodInfos.StringIncludeMethodInfo);
                        }

                        return(null);
                    }
        static int _m_GetGenericMethodDefinition(RealStatePtr L)
        {
            try {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);


                System.Reflection.MethodInfo gen_to_be_invoked = (System.Reflection.MethodInfo)translator.FastGetCSObj(L, 1);



                {
                    System.Reflection.MethodInfo gen_ret = gen_to_be_invoked.GetGenericMethodDefinition(  );
                    translator.Push(L, gen_ret);



                    return(1);
                }
            } catch (System.Exception gen_e) {
                return(LuaAPI.luaL_error(L, "c# exception:" + gen_e));
            }
        }
예제 #5
0
        public static string GetFindableID(this System.Reflection.MethodInfo method, string name = null, string type = null, bool withType = true, bool proxyMethod = false, bool simple = false)
        {
            while (method.IsGenericMethod)
            {
                method = method.GetGenericMethodDefinition();
            }

            StringBuilder builder = new StringBuilder();

            if (simple)
            {
                if (withType)
                {
                    builder.Append(type ?? method.DeclaringType.FullName).Append("::");
                }
                builder.Append(name ?? method.Name);
                return(builder.ToString());
            }

            builder
            .Append(method.ReturnType.FullName)
            .Append(" ");

            if (withType)
            {
                builder.Append(type ?? method.DeclaringType.FullName.Replace("+", "/")).Append("::");
            }

            builder
            .Append(name ?? method.Name);

            if (method.ContainsGenericParameters)
            {
                builder.Append("<");
                Type[] arguments = method.GetGenericArguments();
                for (int i = 0; i < arguments.Length; i++)
                {
                    if (i > 0)
                    {
                        builder.Append(",");
                    }
                    builder.Append(arguments[i].Name);
                }
                builder.Append(">");
            }

            builder.Append("(");

            System.Reflection.ParameterInfo[] parameters = method.GetParameters();
            for (int i = proxyMethod ? 1 : 0; i < parameters.Length; i++)
            {
                System.Reflection.ParameterInfo parameter = parameters[i];
                if (i > (proxyMethod ? 1 : 0))
                {
                    builder.Append(",");
                }

                if (Attribute.IsDefined(parameter, t_ParamArrayAttribute))
                {
                    builder.Append("...,");
                }

                builder.Append(parameter.ParameterType.FullName);
            }

            builder.Append(")");

            return(builder.ToString());
        }