public static void For <T>(EventSourceImplementationAttribute attribute) { if (attribute == null) { throw new ArgumentNullException("attribute"); } _attributes.AddOrUpdate(typeof(T), attribute, (t, a) => a); }
/// <summary> /// Copies the EventSourceAttribute from the interfaceType to a CustomAttributeBuilder. /// </summary> /// <param name="type">The interfaceType to copy.</param> /// <returns>A CustomAttributeBuilder that can be assigned to a type.</returns> internal static CustomAttributeBuilder GetEventSourceAttributeBuilder(Type type) { var attribute = type.GetCustomAttribute <EventSourceAttribute>() ?? new EventSourceAttribute(); var implementation = EventSourceImplementationAttribute.GetAttributeFor(type); // by default, we will use a null guid, which will tell EventSource to generate the guid from the name // but if we have already generated this type, we will have to generate a new one string guid = implementation.Guid ?? attribute.Guid ?? null; if (guid == null) { lock (_typesImplemented) { if (_typesImplemented.Contains(type)) { guid = Guid.NewGuid().ToString(); } else { _typesImplemented.Add(type); } } } var propertyValues = new object[] { implementation.Name ?? attribute.Name ?? (type.IsGenericType ? type.FullName : type.Name), guid, implementation.LocalizationResources ?? attribute.LocalizationResources ?? null }; CustomAttributeBuilder attributeBuilder = new CustomAttributeBuilder( _eventSourceAttributeConstructor, _emptyParameters, _eventSourceAttributePropertyInfo, propertyValues); return(attributeBuilder); }