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);
        }
Пример #2
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);
        }