コード例 #1
0
ファイル: MethodWeaverBase.cs プロジェクト: twaddell/tracer
        internal MethodWeaverBase(TypeReferenceProvider typeReferenceProvider, MethodReferenceProvider methodReferenceProvider,
                                  ILoggerProvider loggerProvider, MethodDefinition methodDefinition)
        {
            _typeReferenceProvider   = typeReferenceProvider;
            _methodReferenceProvider = methodReferenceProvider;
            _methodDefinition        = methodDefinition;
            _body                 = methodDefinition.Body;
            _loggerProvider       = loggerProvider;
            _isEmptyBody          = (_body.Instructions.Count == 0);
            _firstRealInstruction = _body.Instructions.FirstOrDefault();

            if (_body.Method.IsConstructor && !_body.Method.IsStatic)
            {
                var constructorCall = _body.Instructions.FirstOrDefault(IsConstructorCall);
                if (constructorCall != null)
                {
                    var cctrCallIndex = _body.Instructions.IndexOf(constructorCall);
                    if (cctrCallIndex == _body.Instructions.Count - 1)
                    {
                        _isEmptyBody = true;
                    }
                    else
                    {
                        _firstRealInstruction = _body.Instructions[cctrCallIndex + 1];
                    }
                }
            }
        }
コード例 #2
0
 public MethodWeaverFactory(TypeReferenceProvider typeReferenceProvider, MethodReferenceProvider methodReferenceProvider,
                            MethodWeaverBase.ILoggerProvider loggerProvider)
 {
     _typeReferenceProvider   = typeReferenceProvider;
     _methodReferenceProvider = methodReferenceProvider;
     _loggerProvider          = loggerProvider;
 }
コード例 #3
0
ファイル: MethodWeaverBase.cs プロジェクト: ndrwrbgs/aop
        internal MethodWeaverBase(TypeReferenceProvider typeReferenceProvider, MethodReferenceProvider methodReferenceProvider,
                                  ILoggerProvider loggerProvider, MethodDefinition methodDefinition)
        {
            _typeReferenceProvider   = typeReferenceProvider;
            _methodReferenceProvider = methodReferenceProvider;
            _methodDefinition        = methodDefinition;
            _body                 = methodDefinition.Body;
            _loggerProvider       = loggerProvider;
            _isEmptyBody          = (_body.Instructions.Count == 0);
            _firstRealInstruction = _body.Instructions.FirstOrDefault();

            if (_body.Method.IsConstructor && !_body.Method.IsStatic)
            {
                var constructorCall = _body.Instructions.FirstOrDefault(IsConstructorCall);
                if (constructorCall != null)
                {
                    var cctrCallIndex = _body.Instructions.IndexOf(constructorCall);
                    if (cctrCallIndex == _body.Instructions.Count - 1)
                    {
                        _isEmptyBody = true;
                    }
                    else
                    {
                        _firstRealInstruction = _body.Instructions[cctrCallIndex + 1];
                    }
                }
            }

            HasNoTraceOnReturnValue = _methodDefinition.CustomAttributes.Any(attr =>
                                                                             attr.AttributeType.FullName.Equals("TracerAttributes.NoReturnTrace", StringComparison.Ordinal));
        }
コード例 #4
0
 public MethodWeaverFactory(TypeReferenceProvider typeReferenceProvider, MethodReferenceProvider methodReferenceProvider,
     MethodWeaver.ILoggerProvider loggerProvider)
 {
     _typeReferenceProvider = typeReferenceProvider;
     _methodReferenceProvider = methodReferenceProvider;
     _loggerProvider = loggerProvider;
 }
コード例 #5
0
        internal static FieldReference CreateLoggerStaticField(TypeReferenceProvider typeReferenceProvider,
                                                               MethodReferenceProvider methodReferenceProvider,
                                                               TypeDefinition typeDefinition)
        {
            var logTypeRef        = typeReferenceProvider.LogAdapterReference;
            var logManagerTypeRef = typeReferenceProvider.LogManagerReference;

            //look for existing one
            var loggerField = typeDefinition.Fields.FirstOrDefault(fld => fld.IsStatic &&
                                                                   fld.FieldType.FullName.Equals(logTypeRef.FullName));

            if (loggerField != null)
            {
                return(loggerField.FixFieldReferenceIfDeclaringTypeIsGeneric());
            }

            //$log should be unique
            loggerField = new FieldDefinition("$log", FieldAttributes.Private | FieldAttributes.Static, logTypeRef);
            typeDefinition.Fields.Add(loggerField);

            //create field init
            var staticConstructor = typeDefinition.GetStaticConstructor();

            if (staticConstructor == null)
            {
                const MethodAttributes methodAttributes = MethodAttributes.Private | MethodAttributes.Static | MethodAttributes.HideBySig | MethodAttributes.SpecialName | MethodAttributes.RTSpecialName;
                staticConstructor = new MethodDefinition(".cctor", methodAttributes, typeReferenceProvider.Void);
                typeDefinition.Methods.Add(staticConstructor);
                staticConstructor.Body.Instructions.Add(Instruction.Create(OpCodes.Ret));
            }

            var getLoggerMethod = new MethodReference("GetLogger", logTypeRef, logManagerTypeRef);

            getLoggerMethod.Parameters.Add(new ParameterDefinition(typeReferenceProvider.Type));

            //build up typeInfo
            var getTypeFromHandleMethod = methodReferenceProvider.GetGetTypeFromHandleReference();

            //spec treatment for generic types
            var loggerFieldRef = loggerField.FixFieldReferenceIfDeclaringTypeIsGeneric();

            //if generated nested type use the declaring type as logger type as it is more natural from
            //end users perspective
            var hasCompilerGeneratedAttribute = typeDefinition.HasCustomAttributes && typeDefinition.CustomAttributes
                                                .Any(attr => attr.AttributeType.FullName.Equals(typeof(CompilerGeneratedAttribute).FullName, StringComparison.Ordinal));

            var loggerTypeDefinition = hasCompilerGeneratedAttribute && typeDefinition.IsNested
                                                ? typeDefinition.DeclaringType :  typeDefinition;

            staticConstructor.Body.InsertAtTheBeginning(new[]
            {
                Instruction.Create(OpCodes.Ldtoken, loggerTypeDefinition.GetGenericInstantiationIfGeneric()),
                Instruction.Create(OpCodes.Call, getTypeFromHandleMethod),
                Instruction.Create(OpCodes.Call, getLoggerMethod),
                Instruction.Create(OpCodes.Stsfld, loggerFieldRef)
            });

            return(loggerFieldRef);
        }
コード例 #6
0
ファイル: MethodWeaver.cs プロジェクト: ravibpathuri/tracer
 internal MethodWeaver(TypeReferenceProvider typeReferenceProvider, MethodReferenceProvider methodReferenceProvider,
     ILoggerProvider loggerProvider, MethodDefinition methodDefinition)
 {
     _typeReferenceProvider = typeReferenceProvider;
     _methodReferenceProvider = methodReferenceProvider;
     _methodDefinition = methodDefinition;
     _body = methodDefinition.Body;
     _loggerProvider = loggerProvider;
 }
コード例 #7
0
 internal MethodWeaver(TypeReferenceProvider typeReferenceProvider, MethodReferenceProvider methodReferenceProvider,
                       ILoggerProvider loggerProvider, MethodDefinition methodDefinition)
 {
     _typeReferenceProvider   = typeReferenceProvider;
     _methodReferenceProvider = methodReferenceProvider;
     _methodDefinition        = methodDefinition;
     _body           = methodDefinition.Body;
     _loggerProvider = loggerProvider;
 }
コード例 #8
0
        internal AsyncMethodWeaver(TypeReferenceProvider typeReferenceProvider,
                                   MethodReferenceProvider methodReferenceProvider, ILoggerProvider loggerProvider,
                                   MethodDefinition methodDefinition)
            : base(typeReferenceProvider, methodReferenceProvider, loggerProvider, methodDefinition)
        {
            var asyncAttribute = methodDefinition.CustomAttributes.Single(it => it.AttributeType.FullName.Equals(_typeReferenceProvider.AsyncStateMachineAttribute.FullName));

            _generatedType = asyncAttribute.ConstructorArguments[0].Value as TypeDefinition;
            WeavingLog.LogDebug($"Weaving {methodDefinition.FullName}");
        }
コード例 #9
0
 internal MethodWeaverBase(TypeReferenceProvider typeReferenceProvider, MethodReferenceProvider methodReferenceProvider,
                           ILoggerProvider loggerProvider, MethodDefinition methodDefinition)
 {
     _typeReferenceProvider   = typeReferenceProvider;
     _methodReferenceProvider = methodReferenceProvider;
     _methodDefinition        = methodDefinition;
     _body           = methodDefinition.Body;
     _isEmptyBody    = (_body.Instructions.Count == 0);
     _loggerProvider = loggerProvider;
 }
コード例 #10
0
ファイル: TypeWeaverFactory.cs プロジェクト: ndrwrbgs/aop
 public TypeWeaverFactory(ITraceLoggingFilter filter,
                          TypeReferenceProvider typeReferenceProvider,
                          MethodReferenceProvider methodReferenceProvider,
                          bool shouldTraceConstructors,
                          bool shouldTraceProperties)
 {
     _filter = filter;
     _typeReferenceProvider   = typeReferenceProvider;
     _methodReferenceProvider = methodReferenceProvider;
     _shouldTraceConstructors = shouldTraceConstructors;
     _shouldTraceProperties   = shouldTraceProperties;
 }
コード例 #11
0
        private void InternalExecute()
        {
            var typeReferenceProvider = new TypeReferenceProvider(_configuration, this, _moduleDefinition);
            var methodReferenceProvider = new MethodReferenceProvider(typeReferenceProvider, _moduleDefinition);

            var factory = new TypeWeaverFactory(_configuration.Filter, typeReferenceProvider, methodReferenceProvider);
            foreach (var type in _moduleDefinition.GetAllTypes())
            {
                var weaver = factory.Create(type);
                weaver.Execute();
            }
        }
コード例 #12
0
ファイル: TypeWeaver.cs プロジェクト: aniongithub/tracer
 internal TypeWeaver(ITraceLoggingFilter filter, TypeReferenceProvider typeReferenceProvider, MethodReferenceProvider methodReferenceProvider,
                     TypeDefinition typeDefinition)
 {
     _filter = filter;
     _typeReferenceProvider         = typeReferenceProvider;
     _methodReferenceProvider       = methodReferenceProvider;
     _typeDefinition                = typeDefinition;
     _staticLoggerField             = new Lazy <FieldReference>(CreateLoggerStaticField);
     _methodWeaverFactory           = new MethodWeaverFactory(typeReferenceProvider, methodReferenceProvider, this);
     _hasCompilerGeneratedAttribute = new Lazy <bool>(() =>
                                                      _typeDefinition.HasCustomAttributes && _typeDefinition.CustomAttributes
                                                      .Any(attr => attr.AttributeType.FullName.Equals(typeof(CompilerGeneratedAttribute).FullName, StringComparison.Ordinal)));
 }
コード例 #13
0
        private void InternalExecute()
        {
            var typeReferenceProvider   = new TypeReferenceProvider(_configuration, this, _moduleDefinition);
            var methodReferenceProvider = new MethodReferenceProvider(typeReferenceProvider, _moduleDefinition);

            var factory = new TypeWeaverFactory(_configuration.Filter, typeReferenceProvider, methodReferenceProvider);

            foreach (var type in _moduleDefinition.GetAllTypes())
            {
                var weaver = factory.Create(type);
                weaver.Execute();
            }
        }
コード例 #14
0
ファイル: TypeWeaver.cs プロジェクト: ravibpathuri/tracer
 internal TypeWeaver(ITraceLoggingFilter filter, TypeReferenceProvider typeReferenceProvider, MethodReferenceProvider methodReferenceProvider,
     TypeDefinition typeDefinition)
 {
     _filter = filter;
     _typeReferenceProvider = typeReferenceProvider;
     _methodReferenceProvider = methodReferenceProvider;
     _typeDefinition = typeDefinition;
     _staticLoggerField = new Lazy<FieldReference>(CreateLoggerStaticField);
     _methodWeaverFactory = new MethodWeaverFactory(typeReferenceProvider, methodReferenceProvider, this);
     _hasCompilerGeneratedAttribute = new Lazy<bool>(() =>
         _typeDefinition.HasCustomAttributes && _typeDefinition.CustomAttributes
             .Any(attr => attr.AttributeType.FullName.Equals(typeof(CompilerGeneratedAttribute).FullName, StringComparison.Ordinal)));
 }
コード例 #15
0
 internal TypeWeaver(ITraceLoggingFilter filter, bool shouldTraceConstructors, bool shouldTraceProperties, TypeReferenceProvider typeReferenceProvider, MethodReferenceProvider methodReferenceProvider,
                     TypeDefinition typeDefinition)
 {
     _filter = filter;
     _typeReferenceProvider         = typeReferenceProvider;
     _methodReferenceProvider       = methodReferenceProvider;
     _typeDefinition                = typeDefinition;
     _staticLoggerField             = new Lazy <FieldReference>(() => CreateLoggerStaticField(_typeReferenceProvider, _methodReferenceProvider, _typeDefinition));
     _methodWeaverFactory           = new MethodWeaverFactory(typeReferenceProvider, methodReferenceProvider, this);
     _hasCompilerGeneratedAttribute =
         new Lazy <bool>(() => CalculateTypeHasCompilerGeneratedAttribute(typeDefinition));
     _shouldTraceConstructors = shouldTraceConstructors;
     _shouldTraceProperties   = shouldTraceProperties;
 }
コード例 #16
0
ファイル: ModuleLevelWeaver.cs プロジェクト: Janek91/tracer
        private void InternalExecute()
        {
            TypeReferenceProvider   typeReferenceProvider   = new TypeReferenceProvider(_configuration, this, _moduleDefinition);
            MethodReferenceProvider methodReferenceProvider = new MethodReferenceProvider(typeReferenceProvider, _moduleDefinition);

            TypeWeaverFactory factory = new TypeWeaverFactory(_configuration.Filter, typeReferenceProvider, methodReferenceProvider, _configuration.ShouldTraceConstructors,
                                                              _configuration.ShouldTraceProperties);

            foreach (TypeDefinition type in _moduleDefinition.GetAllTypes())
            {
                TypeWeaver weaver = factory.Create(type);
                weaver.Execute();
            }
        }
コード例 #17
0
 public TypeWeaverFactory(ITraceLoggingFilter filter, TypeReferenceProvider typeReferenceProvider, MethodReferenceProvider methodReferenceProvider)
 {
     _filter = filter;
     _typeReferenceProvider   = typeReferenceProvider;
     _methodReferenceProvider = methodReferenceProvider;
 }
コード例 #18
0
ファイル: MethodWeaver.cs プロジェクト: Janek91/tracer
 internal MethodWeaver(TypeReferenceProvider typeReferenceProvider, MethodReferenceProvider methodReferenceProvider,
                       ILoggerProvider loggerProvider, MethodDefinition methodDefinition) : base(typeReferenceProvider, methodReferenceProvider,
                                                                                                 loggerProvider, methodDefinition)
 {
 }
コード例 #19
0
 public TypeWeaverFactory(ITraceLoggingFilter filter, TypeReferenceProvider typeReferenceProvider, MethodReferenceProvider methodReferenceProvider)
 {
     _filter = filter;
     _typeReferenceProvider = typeReferenceProvider;
     _methodReferenceProvider = methodReferenceProvider;
 }