void ProcessType(TypeDefinition type) { var fieldDefinition = type.Fields.FirstOrDefault(x => x.IsStatic && x.FieldType.FullName == LoggerType.FullName); Action foundAction; if (fieldDefinition == null) { fieldDefinition = new FieldDefinition("AnotarLogger", FieldAttributes.Static | FieldAttributes.Private, LoggerType) { DeclaringType = type, IsStatic = true, }; foundAction = () => InjectField(type, fieldDefinition); } else { foundAction = () => { }; } var fieldReference = fieldDefinition.GetGeneric(); var foundUsage = false; foreach (var method in type.Methods) { //skip for abstract and delegates if (!method.HasBody) { continue; } var onExceptionProcessor = new OnExceptionProcessor { Method = method, Field = fieldReference, FoundUsageInType = () => foundUsage = true, ModuleWeaver = this }; onExceptionProcessor.Process(); var logForwardingProcessor = new LogForwardingProcessor { FoundUsageInType = () => foundUsage = true, Method = method, ModuleWeaver = this, Field = fieldReference, }; logForwardingProcessor.ProcessMethod(); } if (foundUsage) { foundAction(); } }
void ProcessType(TypeDefinition type) { var fieldDefinition = type.Fields.FirstOrDefault(x => x.IsStatic && x.FieldType.FullName == LoggerType.FullName); Action foundAction; if (fieldDefinition == null) { fieldDefinition = new FieldDefinition("AnotarLogger", FieldAttributes.Static | FieldAttributes.Private, LoggerType) { DeclaringType = type }; foundAction = () => InjectField(type, fieldDefinition); } else { foundAction = () => { }; } var fieldReference = fieldDefinition.GetGeneric(); var foundUsage = false; foreach (var method in type.Methods) { //skip for abstract and delegates if (!method.HasBody) { continue; } var onExceptionProcessor = new OnExceptionProcessor { Method = method, LoggerField = fieldReference, FoundUsageInType = () => foundUsage = true, ModuleWeaver = this }; onExceptionProcessor.Process(); var logForwardingProcessor = new LogForwardingProcessor { FoundUsageInType = () => foundUsage = true, Method = method, ModuleWeaver = this, LoggerField = fieldReference, }; logForwardingProcessor.ProcessMethod(); } if (foundUsage) { foundAction(); } }
void ProcessType(TypeDefinition type) { foreach (var method in type.Methods) { //skip for abstract and delegates if (!method.HasBody) { continue; } var onExceptionProcessor = new OnExceptionProcessor { Method = method, ModuleWeaver = this }; onExceptionProcessor.Process(); } }