protected virtual Cut LoadArgumentsArgument(Cut pc, AdviceArgument parameter)
        {
            var elements = _method.Parameters.Select <ParameterDefinition, PointCut>(p => il =>
                                                                                     il.Load(p).Cast(p.ParameterType, StandardTypes.Object)
                                                                                     ).ToArray();

            return(pc.CreateArray(StandardTypes.Object, elements));
        }
        protected virtual void LoadArgumentsArgument(PointCut pc, AdviceArgument parameter)
        {
            var elements = _target.Parameters.Select <ParameterDefinition, Action <PointCut> >(p => il =>
                                                                                               il.Load(p).ByVal(p.ParameterType)
                                                                                               ).ToArray();

            pc.CreateArray <object>(elements);
        }
 protected override void LoadInstanceArgument(PointCut pc, AdviceArgument parameter)
 {
     if (_originalThis != null)
     {
         LoadOriginalThis(pc);
     }
     else
     {
         pc.Value((object)null);
     }
 }
 protected virtual void LoadInstanceArgument(PointCut pc, AdviceArgument parameter)
 {
     if (_target.IsStatic)
     {
         pc.Null();
     }
     else
     {
         pc.This();
     }
 }
Пример #5
0
 protected override Cut LoadReturnValueArgument(Cut pc, AdviceArgument parameter)
 {
     if (_retvar == null)
     {
         return(pc.Null());
     }
     else
     {
         return(pc.Load(_retvar).Cast(_retvar.VariableType, StandardTypes.Object));
     }
 }
 protected override Cut LoadInstanceArgument(Cut pc, AdviceArgument parameter)
 {
     if (_originalThis != null)
     {
         return(LoadOriginalThis(pc));
     }
     else
     {
         return(pc.Value(null));
     }
 }
Пример #7
0
 protected override void LoadReturnValueArgument(PointCut pc, AdviceArgument parameter)
 {
     if (_retvar == null)
     {
         pc.Null();
     }
     else
     {
         pc.Load(_retvar).Cast(_retvar.VariableType, _ts.Object);
     }
 }
Пример #8
0
        protected override void LoadTargetArgument(PointCut pc, AdviceArgument parameter)
        {
            var targetFuncType = _ts.MakeGenericInstanceType(
                _ts.FuncGeneric2,
                _ts.ObjectArray,
                _ts.Object);

            var targetFuncCtor = targetFuncType.Resolve().Methods.First(m => m.IsConstructor && !m.IsStatic).MakeHostInstanceGeneric(targetFuncType);
            var targetMethod   = _wrapper.MakeCallReference(GetOrCreateUnwrapper().MakeHostInstanceGeneric(_target.DeclaringType));

            pc.ThisOrNull().Call(targetFuncCtor, args => args.Load(targetMethod));
        }
Пример #9
0
        protected virtual Cut LoadInjectionsArgument(Cut pc, AdviceArgument parameter)
        {
            var elements = _injection.Triggers.Select <CustomAttribute, PointCut>(ca => il =>
            {
                var ctor = ca.Constructor.Resolve();

                il = il.Call(ctor, new PointCut(ilc =>
                {
                    foreach (var caa in ca.ConstructorArguments)
                    {
                        ilc = ilc.Value(caa);
                    }
                    return(ilc);
                }));

                if (ca.Properties.Any() || ca.Fields.Any())
                {
                    var catype = ca.AttributeType.Resolve();

                    var attrvar = new VariableDefinition(il.Import(ca.AttributeType));
                    _target.Body.Variables.Add(attrvar);
                    _target.Body.InitLocals = true;

                    il = il.Store(attrvar);

                    foreach (var namedArg in ca.Properties)
                    {
                        var prop = catype.Properties.First(p => p.Name == namedArg.Name).SetMethod;

                        il = il
                             .Load(attrvar)
                             .Call(prop, ilp => ilp.Value(namedArg.Argument));
                    }

                    foreach (var namedArg in ca.Fields)
                    {
                        var field = catype.Fields.First(p => p.Name == namedArg.Name);

                        il = il
                             .Load(attrvar)
                             .Store(field, ilf => ilf.Value(namedArg.Argument));
                    }
                    il = il.Load(attrvar);
                }

                return(il);
            }
                                                                                  ).ToArray();

            return(pc.CreateArray(StandardTypes.Attribute, elements));
        }
        protected virtual Cut LoadInjectionsArgument(Cut pc, AdviceArgument parameter)
        {
            var elements = _injection.Triggers.Select <CustomAttribute, PointCut>(ca => il =>
            {
                var ctor = ca.Constructor.Resolve();

                il = il.Call(ctor, new PointCut(ilc =>
                {
                    foreach (var caa in ca.ConstructorArguments)
                    {
                        ilc = ilc.Value(caa);
                    }
                    return(ilc);
                }));

                if (ca.Properties.Any() || ca.Fields.Any())
                {
                    var catype = ca.AttributeType.Resolve();

                    foreach (var namedArg in ca.Properties)
                    {
                        var prop = catype.FindProperty(namedArg.Name).SetMethod;

                        il = il
                             .Dup()
                             .Call(prop, ilp => ilp.Value(namedArg.Argument));
                    }

                    foreach (var namedArg in ca.Fields)
                    {
                        var field = catype.FindField(namedArg.Name);

                        il = il
                             .Dup()
                             .Store(field, ilf => ilf.Value(namedArg.Argument));
                    }
                }

                return(il);
            }
                                                                                  ).ToArray();

            return(pc.CreateArray(StandardTypes.Attribute, elements));
        }
Пример #11
0
        protected virtual void LoadInjectionsArgument(PointCut pc, AdviceArgument parameter)
        {
            var elements = _injection.Triggers.Select <CustomAttribute, Action <PointCut> >(ca => il =>
            {
                var ctor = ca.Constructor.Resolve();
                void ctorParams(PointCut ilc) => ca.ConstructorArguments.Select(caa => ilc.Value(caa)).ToArray();
                il.Call(ctor, ctorParams);

                if (ca.Properties.Any() || ca.Fields.Any())
                {
                    var catype = ca.AttributeType.Resolve();

                    var attrvar = new VariableDefinition(_ts.Import(ca.AttributeType));
                    _target.Body.Variables.Add(attrvar);
                    _target.Body.InitLocals = true;

                    il.Store(attrvar);

                    foreach (var namedArg in ca.Properties)
                    {
                        var prop = catype.Properties.First(p => p.Name == namedArg.Name).SetMethod;

                        il.Load(attrvar);
                        il.Call(prop, ilp => ilp.Value(namedArg.Argument));
                    }

                    foreach (var namedArg in ca.Fields)
                    {
                        var field = catype.Fields.First(p => p.Name == namedArg.Name);

                        il.Load(attrvar);
                        il.Store(field, ilf => ilf.Value(namedArg.Argument));
                    }
                    il.Load(attrvar);
                }
            }
                                                                                            ).ToArray();

            pc.CreateArray(_ts.Attribute, elements);
        }
 protected virtual void LoadNameArgument(PointCut pc, AdviceArgument parameter)
 {
     pc.Value(_target.Name);
 }
 protected virtual void LoadTypeArgument(PointCut pc, AdviceArgument parameter)
 {
     pc.TypeOf(_target.DeclaringType);
 }
 protected virtual void LoadAttributesArgument(PointCut pc, AdviceArgument parameter)
 {
     pc.Null();
 }
 protected virtual Cut LoadInstanceArgument(Cut pc, AdviceArgument parameter)
 {
     return(pc.ThisOrNull());
 }
Пример #16
0
        protected override Cut LoadTargetArgument(Cut pc, AdviceArgument parameter)
        {
            var targetMethod = CreateRef(GetOrCreateUnwrapper(), pc.Method);

            return(pc.ThisOrNull().Call(CreateFuncCtorRef(pc), args => args.Delegate(targetMethod)));
        }
Пример #17
0
 protected override Cut LoadArgumentsArgument(Cut pc, AdviceArgument parameter)
 {
     return(pc.Load(_wrapper.Parameters[0]));
 }
Пример #18
0
 protected virtual void LoadReturnValueArgument(PointCut pc, AdviceArgument parameter)
 {
     pc.Null();
 }
 protected override Cut LoadReturnTypeArgument(Cut pc, AdviceArgument parameter)
 {
     return(pc.TypeOf(_asyncResult ?? StandardTypes.Void));
 }
 protected virtual void LoadMethodArgument(PointCut pc, AdviceArgument parameter)
 {
     pc.MethodOf(_target).Cast(_ts.MethodBase);
 }
Пример #21
0
 protected override void LoadReturnTypeArgument(PointCut pc, AdviceArgument parameter)
 {
     pc.TypeOf(_asyncResult ?? _ts.Void);
 }
 protected override Cut LoadArgumentsArgument(Cut pc, AdviceArgument parameter)
 {
     return(pc.This().Load(GetArgsField()));
 }
 protected override void LoadReturnTypeArgument(PointCut pc, AdviceArgument parameter)
 {
     pc.TypeOf(_stateMachine.Interfaces.First(i => i.Name.StartsWith("IEnumerable`1")));
 }
Пример #24
0
 protected override void LoadArgumentsArgument(PointCut pc, AdviceArgument parameter)
 {
     pc.Load(_wrapper.Parameters[0]);
 }
 protected virtual void LoadReturnValueArgument(PointCut pc, AdviceArgument parameter)
 {
     _log.LogWarning(CompilationMessage.From($"Advice {_effect.Type.ToString()} does not support {parameter.Source.ToString()} argument and will always return null", _effect.Method));
     pc.Null();
 }
Пример #26
0
 protected override void LoadReturnValueArgument(PointCut pc, AdviceArgument parameter)
 {
     pc.Load(pc.Method.Parameters[0]);
 }
 protected virtual void LoadReturnTypeArgument(PointCut pc, AdviceArgument parameter)
 {
     pc.TypeOf(_target.ReturnType);
 }
 protected override Cut LoadReturnValueArgument(Cut pc, AdviceArgument parameter)
 {
     return(pc.Load(pc.Method.Parameters[0]));
 }
 protected override void LoadReturnValueArgument(PointCut pc, AdviceArgument parameter)
 {
     pc.This();
 }
Пример #30
0
 protected virtual void LoadTargetArgument(PointCut pc, AdviceArgument parameter)
 {
     pc.Null();
 }