Пример #1
0
        public override void Build(BuildContext context)
        {
            Context = context;

            FieldBuilder methodInfo = Context.CreatePrivateStaticField(
                "_methodInfo$ClearCacheAspect$" + ++_methodCounter, typeof(MethodInfo));

            EmitHelper emit = Context.MethodBuilder.Emitter;

            Label checkMethodInfo = emit.DefineLabel();

            emit
            .ldsfld(methodInfo)
            .brtrue_s(checkMethodInfo)
            .ldarg_0
            .LoadType(_declaringType)
            .ldstr(_methodName)
            ;

            if (_parameterTypes == null || _parameterTypes.Length == 0)
            {
                emit.ldnull.end();
            }
            else
            {
                LocalBuilder field = emit.DeclareLocal(typeof(Type[]));

                emit
                .ldc_i4_(_parameterTypes.Length)
                .newarr(typeof(Type))
                .stloc(field)
                ;

                for (int i = 0; i < _parameterTypes.Length; i++)
                {
                    emit
                    .ldloc(field)
                    .ldc_i4(i)
                    .LoadType(_parameterTypes[i])
                    .stelem_ref
                    .end()
                    ;
                }

                emit.ldloc(field);
            }

            emit
            .call(typeof(ClearCacheAspect), "GetMethodInfo", typeof(object), typeof(Type), typeof(string), typeof(Type[]))
            .stsfld(methodInfo)
            .MarkLabel(checkMethodInfo)
            .ldsfld(methodInfo)
            .call(typeof(CacheAspect), "ClearCache", typeof(MethodInfo))
            ;
        }