vc3/Afterthought — Issue #37: Multiple amendments for the same type
Author: kovapie
Created: 2012-02-02 11:30:25+00:00
State: open

Hi,

It seems that we cannot have more than one amendment per type.

The code to amend a type is based on a dictionary using the type name as a key.

bool AmendType(NamedTypeDefinition type)
{
....
// Get the Amendment for the current type definition
ITypeAmendment typeAmendment;
typeAmendments.TryGetValue(type.ToString(), out typeAmendment);

The code crashes in the AssemblyAmender constructor where the dictionary is built

this.typeAmendments = typeAmendments.ToDictionary(w => w.Type.FullName);

because different ITypeAmendment implementations exist for the same type.

Can you confirm this is the case or am I missing something?

Currently my 2 implementations of IAmendmentAttribute are based on the NotificationAmenderAttribute:

public class NotificationAmenderAttribute : Attribute, IAmendmentAttribute
{
IEnumerable IAmendmentAttribute.GetAmendments(Type target)
{
if (target.GetCustomAttributes(typeof(NotifyPropertyChangedAttribute), true).Length > 0 && target.GetInterface("System.ComponentModel.INotifyPropertyChanged") == null)
yield return (ITypeAmendment)typeof(NotificationAmendment<>).MakeGenericType(target).GetConstructor(Type.EmptyTypes).Invoke(new object[0]);

}
}

Many thanks,
Pierre