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]; } } } }
public MethodWeaverFactory(TypeReferenceProvider typeReferenceProvider, MethodReferenceProvider methodReferenceProvider, MethodWeaverBase.ILoggerProvider loggerProvider) { _typeReferenceProvider = typeReferenceProvider; _methodReferenceProvider = methodReferenceProvider; _loggerProvider = loggerProvider; }
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)); }
public MethodWeaverFactory(TypeReferenceProvider typeReferenceProvider, MethodReferenceProvider methodReferenceProvider, MethodWeaver.ILoggerProvider loggerProvider) { _typeReferenceProvider = typeReferenceProvider; _methodReferenceProvider = methodReferenceProvider; _loggerProvider = loggerProvider; }
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); }
internal MethodWeaver(TypeReferenceProvider typeReferenceProvider, MethodReferenceProvider methodReferenceProvider, ILoggerProvider loggerProvider, MethodDefinition methodDefinition) { _typeReferenceProvider = typeReferenceProvider; _methodReferenceProvider = methodReferenceProvider; _methodDefinition = methodDefinition; _body = methodDefinition.Body; _loggerProvider = loggerProvider; }
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}"); }
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; }
public TypeWeaverFactory(ITraceLoggingFilter filter, TypeReferenceProvider typeReferenceProvider, MethodReferenceProvider methodReferenceProvider, bool shouldTraceConstructors, bool shouldTraceProperties) { _filter = filter; _typeReferenceProvider = typeReferenceProvider; _methodReferenceProvider = methodReferenceProvider; _shouldTraceConstructors = shouldTraceConstructors; _shouldTraceProperties = shouldTraceProperties; }
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(); } }
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))); }
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))); }
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; }
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(); } }
public TypeWeaverFactory(ITraceLoggingFilter filter, TypeReferenceProvider typeReferenceProvider, MethodReferenceProvider methodReferenceProvider) { _filter = filter; _typeReferenceProvider = typeReferenceProvider; _methodReferenceProvider = methodReferenceProvider; }
internal MethodWeaver(TypeReferenceProvider typeReferenceProvider, MethodReferenceProvider methodReferenceProvider, ILoggerProvider loggerProvider, MethodDefinition methodDefinition) : base(typeReferenceProvider, methodReferenceProvider, loggerProvider, methodDefinition) { }