in PostSharp Laos.
So what's aggregation?
Say you want to implement a collection (ICollection) based on an ArrayList, but you want to hide ArrayList and don't want to implement each method manually. PostSharp can do it for you.
Look at the following code sample:
[SimpleAggregate(After processing by PostSharp, the AggregatedCollection class will implement the ICollection collection using the ArrayList implementation.ImplementationType=typeof(ArrayList),
InterfaceType=typeof(ICollection))]
internal class AggregatedCollection
{
}
Looks magic? If you inspect the generated code (the Roeder's Reflector is always useful for this), you will see a new field ~aggregated~0 of type ICollection and all methods of this interface, for instance:
IEnumerator IEnumerable.GetEnumerator()The aggregated object is constructed inside the constructor of AggregatedCollection:{
return this.~aggregated~0.GetEnumerator();
}
public AggregatedCollection()Still looks magic?{
this.~aggregated~0 = (ICollection)
~PostSharp~Laos~Implementation.customAttribute0.
CreateAggregatedObject(this);
}