private static void HandleMethod(HandleMethodArgs args) { Globals.Loggers.File.Debug("Handling method {0}.", args.MethodDefinition.FullName); if (args.MethodDefinition.HasCustomAttributes) { Globals.Loggers.File.Trace("Handling method custom attributes."); for (var i = 0; i < args.MethodDefinition.CustomAttributes.Count; i++) { var attribute = args.MethodDefinition.CustomAttributes[i]; var handleAttributeArgs = new HandleMethodAttributeArgs { CustomAttribute = attribute, MethodAttributeNames = args.MethodAttributeNames, MethodDefinition = args.MethodDefinition }; if (HandleMethodAttribute(handleAttributeArgs)) { i--; } } } else { Globals.Loggers.File.Trace("Method does not has custom attributes."); } }
private static bool HandleMethodAttribute(HandleMethodAttributeArgs args) { var attributeTypeName = args.CustomAttribute.AttributeType.FullName; Globals.Loggers.File.Trace("Handling attribute {0}.", attributeTypeName); bool result; if (args.MethodAttributeNames.Contains(attributeTypeName)) { var processor = args.MethodDefinition.Body.GetILProcessor(); var instructionBuilder = new InstructionBuilders.MethodAttributeBase(processor, args.CustomAttribute); instructionBuilder.Inject(); Globals.Loggers.Global.Info("Attribute {0} logic injected into {1} method.", args.CustomAttribute.AttributeType.FullName, args.MethodDefinition.FullName); args.MethodDefinition.CustomAttributes.Remove(args.CustomAttribute); result = true; } else { Globals.Loggers.File.Trace("Attribute is not inheritor of MethodAttributeBase."); result = false; } return(result); }
private static void HandleMethod(HandleMethodArgs args) { Globals.Loggers.File.Debug("Handling method {0}.", args.MethodDefinition.FullName); if (args.MethodDefinition.HasCustomAttributes) { Globals.Loggers.File.Trace("Handling method custom attributes."); for (var i = 0; i < args.MethodDefinition.CustomAttributes.Count; i++ ) { var attribute = args.MethodDefinition.CustomAttributes[i]; var handleAttributeArgs = new HandleMethodAttributeArgs { CustomAttribute = attribute, MethodAttributeNames = args.MethodAttributeNames, MethodDefinition = args.MethodDefinition }; if (HandleMethodAttribute(handleAttributeArgs)) { i--; } } } else { Globals.Loggers.File.Trace("Method does not has custom attributes."); } }
private static bool HandleMethodAttribute(HandleMethodAttributeArgs args) { var attributeTypeName = args.CustomAttribute.AttributeType.FullName; Globals.Loggers.File.Trace("Handling attribute {0}.", attributeTypeName); bool result; if (args.MethodAttributeNames.Contains(attributeTypeName)) { var processor = args.MethodDefinition.Body.GetILProcessor(); var instructionBuilder = new InstructionBuilders.MethodAttributeBase(processor, args.CustomAttribute); instructionBuilder.Inject(); Globals.Loggers.Global.Info("Attribute {0} logic injected into {1} method.", args.CustomAttribute.AttributeType.FullName, args.MethodDefinition.FullName); args.MethodDefinition.CustomAttributes.Remove(args.CustomAttribute); result = true; } else { Globals.Loggers.File.Trace("Attribute is not inheritor of MethodAttributeBase."); result = false; } return result; }