コード例 #1
0
 private static Coder ImplementOnEnterMethod(
     Coder coder,
     MethodBuilderInfo <MethodBuilderInfoItem <BuilderTypeIMethodInterceptor, BuilderTypeISimpleMethodInterceptor> > method,
     Method attributedMethod,
     MethodBuilderInfoItem <BuilderTypeIMethodInterceptor, BuilderTypeISimpleMethodInterceptor>[] fullMethodInterceptors,
     Func <MethodBuilderInfoItem <BuilderTypeIMethodInterceptor, BuilderTypeISimpleMethodInterceptor>, Method> onEnterMethod)
 => ImplementOnEnterMethod(coder, coder, coder, method, attributedMethod, fullMethodInterceptors, onEnterMethod);
コード例 #2
0
    private static Coder ImplementOnExitMethod(
        Coder coder,
        MethodBuilderInfo <MethodBuilderInfoItem <BuilderTypeIMethodInterceptor, BuilderTypeISimpleMethodInterceptor> > method,
        MethodBuilderInfoItem <BuilderTypeIMethodInterceptor, BuilderTypeISimpleMethodInterceptor>[] fullMethodInterceptors)
    {
        for (int i = 0; i < fullMethodInterceptors.Length; i++)
        {
            if (fullMethodInterceptors[i].HasOnExitInterface)
            {
                if (method.Key.Method.ReturnType == BuilderTypes.Void)
                {
                    if (fullMethodInterceptors[i].FieldOrVariable is Field field)
                    {
                        coder.Load(field)
                        .As(BuilderTypes.IMethodInterceptorOnExit)
                        .Call(BuilderTypes.IMethodInterceptorOnExit.GetMethod_OnExit(), BuilderTypes.Void, null)
                        .Pop();
                    }
                    else if (fullMethodInterceptors[i].FieldOrVariable is LocalVariable localVariable)
                    {
                        coder.Load(localVariable)
                        .As(BuilderTypes.IMethodInterceptorOnExit)
                        .Call(BuilderTypes.IMethodInterceptorOnExit.GetMethod_OnExit(), BuilderTypes.Void, null)
                        .Pop();
                    }
                }
                else
                {
                    coder.SetValue(coder.GetOrCreateReturnVariable(), y =>
                    {
                        if (fullMethodInterceptors[i].FieldOrVariable is Field field)
                        {
                            y.Load(field)
                            .As(BuilderTypes.IMethodInterceptorOnExit)
                            .Call(BuilderTypes.IMethodInterceptorOnExit.GetMethod_OnExit(), method.Key.Method.ReturnType, y.GetOrCreateReturnVariable());
                        }
                        else if (fullMethodInterceptors[i].FieldOrVariable is LocalVariable localVariable)
                        {
                            y.Load(localVariable)
                            .As(BuilderTypes.IMethodInterceptorOnExit)
                            .Call(BuilderTypes.IMethodInterceptorOnExit.GetMethod_OnExit(), method.Key.Method.ReturnType, y.GetOrCreateReturnVariable());
                        }

                        return(y);
                    });
                }
            }
            else
            {
                coder.Load <ICallMethod <CallCoder> >(fullMethodInterceptors[i].FieldOrVariable).Call(fullMethodInterceptors[i].InterfaceA.GetMethod_OnExit());
            }
        }

        return(coder);
    }
コード例 #3
0
    private static Coder ImplementOnEnterMethod(
        Coder originCoder,
        Coder outerCoder,
        Coder innerCoder,
        MethodBuilderInfo <MethodBuilderInfoItem <BuilderTypeIMethodInterceptor, BuilderTypeISimpleMethodInterceptor> > method,
        Method attributedMethod,
        MethodBuilderInfoItem <BuilderTypeIMethodInterceptor, BuilderTypeISimpleMethodInterceptor>[] fullMethodInterceptors,
        Func <MethodBuilderInfoItem <BuilderTypeIMethodInterceptor, BuilderTypeISimpleMethodInterceptor>, Method> onEnterMethod)
    {
        for (int i = 0; i < fullMethodInterceptors.Length; i++)
        {
            innerCoder.Load <ICallMethod <CallCoder> >(fullMethodInterceptors[i].FieldOrVariable).Call(onEnterMethod(fullMethodInterceptors[i]), attributedMethod.OriginType, originCoder.AssociatedMethod.AsyncMethodHelper.Instance, attributedMethod,
                                                                                                       method.Key.Method.Parameters.Length > 0 ? outerCoder.GetParametersArray() : null);
        }

        return(innerCoder);
    }
コード例 #4
0
        public static void AddThisReferenceToAsyncMethod(this MethodBuilderInfo method)
        {
            var attributedMethod = method.Key.Method;
            var targetedMethod   = method.Key.AsyncMethod == null ? method.Key.Method : method.Key.AsyncMethod;

            if (method.Key.AsyncMethod != null && !targetedMethod.DeclaringType.Fields.Any(x => x.Name == "<>4__this"))
            {
                var thisField = targetedMethod.DeclaringType.CreateField(Modifiers.Public, attributedMethod.DeclaringType, "<>4__this");
                var position  = attributedMethod.AsyncMethodHelper.GetAsyncTaskMethodBuilderInitialization();

                if (position == null)
                {
                    attributedMethod.NewCode().LoadVariable(0).Assign(thisField).Set(attributedMethod.NewCode().This).Insert(InsertionPosition.Beginning);
                }
                else
                {
                    attributedMethod.NewCode().LoadVariable(0).Assign(thisField).Set(attributedMethod.NewCode().This).Insert(InsertionAction.After, position);
                }
            }
        }
コード例 #5
0
        internal MethodBuilder EnsureMethodBuilder(TypeBuilder typeBuilder, string methodName,
                                                   MethodAttributes attributes, Type returnType, Type[] parameterTypes)
        {
            MethodBuilderInfo methodBuilderInfo;

            if (!_methodBuilders.TryGetValue(methodName, out methodBuilderInfo))
            {
                MethodBuilder methodBuilder = typeBuilder.DefineMethod(
                    methodName,
                    attributes,
                    returnType,
                    parameterTypes);
                methodBuilderInfo = new MethodBuilderInfo(methodBuilder, parameterTypes);
                _methodBuilders.Add(methodName, methodBuilderInfo);
            }
#if DEBUG
            else
            {
                methodBuilderInfo.Validate(returnType, parameterTypes, attributes);
            }
#endif
            return(methodBuilderInfo.MethodBuilder);
        }
コード例 #6
0
        public static object GetAsyncMethodTypeInstace(this MethodBuilderInfo method)
        {
            var targetedMethod = method.Key.AsyncMethod == null ? method.Key.Method : method.Key.AsyncMethod;

            return(method.Key.AsyncMethod == null ? (object)targetedMethod.NewCode().This : targetedMethod.DeclaringType.Fields.FirstOrDefault(x => x.Name == "<>4__this"));
        }
コード例 #7
0
ファイル: BuilderExtensions.cs プロジェクト: Kazpers/Cauldron
        public static object GetAsyncMethodTypeInstace <T>(this MethodBuilderInfo <T> method) where T : IMethodBuilderInfoItem
        {
            var targetedMethod = method.Key.AsyncMethod ?? method.Key.Method;

            return(method.Key.AsyncMethod == null ? (object)Crumb.This : targetedMethod.DeclaringType.Fields.FirstOrDefault(x => x.Name == "<>4__this"));
        }