private TraceAttributeInfo GetNearestTraceAttributeWalkingUpTheTypeNestingChain(TypeDefinition type) { //with NoTrace present skip tracing if (type.CustomAttributes.Any( attr => attr.AttributeType.FullName.Equals("TracerAttributes.NoTrace", StringComparison.Ordinal))) { return(TraceAttributeInfo.NoTrace()); } var traceOnAttribute = type.CustomAttributes.FirstOrDefault( attr => attr.AttributeType.FullName.Equals("TracerAttributes.TraceOn", StringComparison.Ordinal)); if (traceOnAttribute != null) { return(TraceAttributeInfo.TraceOn(GetTargetVisibilityFromAttribute(traceOnAttribute))); } //no attrib present on type see if we have an outer class if (type.DeclaringType != null) { return(GetNearestTraceAttributeWalkingUpTheTypeNestingChain(type.DeclaringType)); } return(null); }
private TraceAttributeInfo GetTraceAttributeInfoForType(TypeDefinition type) { TraceAttributeInfo result = null; if (!_traceAttributeCache.TryGetValue(type.FullName, out result)) { result = GetNearestTraceAttributeWalkingUpTheTypeNestingChain(type); _traceAttributeCache.Add(type.FullName, result); } return(result); }
private bool?ShouldTraceBasedOnClassLevelInfo(MethodDefinition definition) { TraceAttributeInfo attributeInfo = GetTraceAttributeInfoForType(definition.DeclaringType); if (attributeInfo != null) { if (attributeInfo.IsNoTrace) { return(false); } TraceTargetVisibility targetVisibility = attributeInfo.TargetVisibility; VisibilityLevel methodVisibility = VisibilityHelper.GetMethodVisibilityLevel(definition); return((int)targetVisibility >= (int)methodVisibility); } return(null); }