Attribute multicasting was designed primarily as a mechanism to add aspects to a program. Most of the time, the custom attribute representing an aspect can be removed after the aspect has been applied.
By default, if you add an aspect to a program and look at the resulting program using a disassembler or System.Reflection, you will not find these corresponding custom attributes.
If you need your aspect (or any other multicast attribute) to be reflected by System.Reflection or any other tool, you have to set the PersistMetaData property to true.
For instance:
[MulticastAttributeUsage( MulticastTargets.Class, PersistMetaData = true )]
public class TagAttribute : MulticastAttribute
{
public string? Tag;
}
Suppose that this attribute is multicast to some classes with the following line:
[assembly: Tag( Tag = "business", AttributeTargetTypes = "MulticastReflection.Customer*" )]
A program that reads the attribute of each class with System.Reflection then finds it on the classes Customer and CustomerRepository, but not on the class Logger:
Customer: business
CustomerRepository: business
Logger: (no tag)
Note
Multicasting of attributes is not limited to PostSharp aspects. You can multicast any custom attribute in your codebase in the same way as shown here. If a custom attribute is multicast with the PersistMetaData property set to true, the compiled code, when reflected, looks as if you had manually added the custom attribute in all of the locations.