private static async Task <TResult> ExecuteAsync <TSource, TResult>(System.Reflection.MethodInfo method, IQueryable <TSource> source, IEnumerable <object> args, CancellationToken cancellationToken)
        {
            if (source.Provider is IAsyncRemoteQueryProvider asyncQueryableProvider)
            {
                if (method.IsGenericMethodDefinition)
                {
                    if (method.GetGenericArguments().Length > 2)
                    {
                        throw new Exception("Implementation error: expected closed generic method definition.");
                    }

                    method = method.GetGenericArguments().Length == 2
                        ? method.MakeGenericMethod(typeof(TSource), typeof(TResult))
                        : method.MakeGenericMethod(typeof(TSource));
                }

                var arguments = new[] { source.Expression }
                .Concat(args.Select(x => x is Expression exp ? (Expression)Expression.Quote(exp) : Expression.Constant(x)))
                .ToArray();
                var methodCallExpression = Expression.Call(null, method, arguments);

                return(await asyncQueryableProvider.ExecuteAsync <TResult>(methodCallExpression, cancellationToken).ConfigureAwait(false));
            }

            throw InvalidProviderException;
        }
Beispiel #2
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);
        }
Beispiel #3
0
        public static bool MatchGenericParameters(this System.Reflection.MethodInfo m, Type[] genericArguments, Type returnType, params Type[] parameters)
        {
            var param = m.GetParameters();

            if (param.Length == parameters.Length)
            {
                var args = m.GetGenericArguments();
                if (args.MatchGenericParameters(m.ReturnType, returnType, genericArguments))
                {
                    for (int i = 0; i < param.Length; i++)
                    {
                        if (!args.MatchGenericParameters(param[i].ParameterType, parameters[i], genericArguments))
                        {
                            return(false);
                        }
                    }

                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
Beispiel #4
0
        Func <IMethodCallMessage, IMethodReturnMessage> CreateRefCountHandler(IMethodCallMessage call, System.Reflection.MethodInfo method, OperatorInfo operatorInfo)
        {
            var signalType = method.GetGenericArguments()[0];
            var connectableOperatorConnectionType = typeof(ConnectableOperatorConnection <>).MakeGenericType(signalType);

            return(c => HandleRefCount(c, method, connectableOperatorConnectionType, signalType, operatorInfo));
        }
Beispiel #5
0
        public MethodInfo(System.Reflection.MethodInfo methodInfo, XElement xmlDocs)
        {
            Method = methodInfo;

            Parameters = methodInfo.GetParameters().ToList();

            GenericArguments = methodInfo.GetGenericArguments().ToList();
        }
Beispiel #6
0
        internal CILMethodImpl(
            CILReflectionContextImpl ctx,
            Int32 anID,
            System.Reflection.MethodInfo method
            )
            : base(ctx, anID, method)
        {
            var nGDef = method.IsGenericMethodDefinition ? method : null;

            var dllImportAttr = method.GetCustomAttributes(typeof(System.Runtime.InteropServices.DllImportAttribute), true).FirstOrDefault() as System.Runtime.InteropServices.DllImportAttribute;

            InitFields(
                ref this.name,
                ref this.returnParameter,
                ref this.gArgs,
                ref this.gArgsLock,
                ref this.gDef,
                ref this.overriddenMethods,
                ref this.overriddenMethodsLock,
                ref this.pInvokeAttributes,
                ref this.pInvokeName,
                ref this.pInvokeModule,
                new SettableValueForClasses <String>(method.Name),
                () => ctx.Cache.GetOrAdd(method.ReturnParameter),
                () => ctx.CollectionsFactory.NewListProxy <CILTypeBase>(method.GetGenericArguments().Select(gArg => ctx.Cache.GetOrAdd(gArg)).ToList()),
                () => ctx.Cache.GetOrAdd(nGDef),
                () =>
            {
                var result = this.context.CollectionsFactory.NewListProxy <CILMethod>();

                if (!method.DeclaringType
#if WINDOWS_PHONE_APP
                    .GetTypeInfo()
#endif
                    .IsInterface&& !method.IsPublic)
                {
                    var args = new ExplicitMethodImplementationLoadArgs(method.DeclaringType);
                    ctx.LaunchInterfaceMappingLoadEvent(args);
                    System.Reflection.MethodInfo[] resultNMethods;
                    if (args.ExplicitlyImplementedMethods.TryGetValue(method, out resultNMethods))
                    {
                        result.AddRange(resultNMethods.Select(nMethod => ctx.Cache.GetOrAdd(nMethod)));
                    }
                }
                return(result);
            },
                new SettableValueForEnums <PInvokeAttributes>(dllImportAttr == null ? (PInvokeAttributes)0 : dllImportAttr.GetCorrespondingPInvokeAttributes()),
                new SettableValueForClasses <String>(dllImportAttr == null ? null : dllImportAttr.EntryPoint),
                new SettableValueForClasses <String>(dllImportAttr == null ? null : dllImportAttr.Value),
                true
                );
        }
Beispiel #7
0
        public static Method ReverseEngineer(System.Reflection.MethodInfo _method)
        {
            Method method = new Method();

            //decompile method body
            if (!_method.IsAbstract && !_method.IsCompilerGenerated())
            {
                Mono.Cecil.AssemblyDefinition ass = Decompiler.LoadAssembly(_method.DeclaringType.Module.Assembly.Location);
                MethodDefinition md = ass.MainModule.GetType(_method.DeclaringType.FullName).Methods.Where(md2 => md2.Name == _method.Name).Select(md2 => md2).First();
                method.MethodCode = Decompiler.GetSourceCode(md);
            }

            method.Name       = _method.Name;
            method.Type       = ReverseEngineer(_method.DeclaringType);
            method.ReturnType = ReverseEngineer(_method.ReturnType);
            method.IsStatic   = _method.IsStatic;
            method.IsAbstract = _method.IsAbstract;
            method.IsVirtual  = _method.IsVirtual;
            method.Access     = _method.GetAccessModifier();

            DataBase.Current.Set <Method>().Add(method);

            foreach (System.Reflection.ParameterInfo _param in _method.GetParameters())
            {
                MethodArgument ma = new MethodArgument();
                ma.Method = method;
                ma.Name   = _param.Name;
                ma.Type   = ReverseEngineer(_param.ParameterType);

                DataBase.Current.Set <MethodArgument>().Add(ma);
            }

            if (_method.IsGenericMethod || _method.IsGenericMethodDefinition || _method.ContainsGenericParameters)
            {
                foreach (System.Type _genericArg in _method.GetGenericArguments())
                {
                    MethodGenericArgument genericArg = new MethodGenericArgument();

                    genericArg.ArgumentType = ReverseEngineer(_genericArg);
                    genericArg.Position     = _genericArg.GenericParameterPosition;
                    genericArg.AppliedTo    = method;

                    DataBase.Current.Set <MethodGenericArgument>().Add(genericArg);
                }
            }

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


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



                {
                    System.Type[] gen_ret = gen_to_be_invoked.GetGenericArguments(  );
                    translator.Push(L, gen_ret);



                    return(1);
                }
            } catch (System.Exception gen_e) {
                return(LuaAPI.luaL_error(L, "c# exception:" + gen_e));
            }
        }
Beispiel #9
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());
        }