public void Weave(IWeavingContext weavingContext, TypeDefinition target, CustomAttribute weaveAttribute)
{
if (weaveAttribute.AttributeType.FullName != weavingContext.GetTypeDefinition(typeof(InterfaceMixinAttribute)).FullName)
{
throw new ArgumentException("Must be a valid CustomAttribute with AttributeType InterfaceMixAttribute",
"weaveAttribute");
}
if (weaveAttribute.ConstructorArguments.Count != 1)
{
throw new ArgumentException("Expected a single constructor argument", "weaveAttribute");
}
var mixinInterfaceTypeReference = weaveAttribute.ConstructorArguments[0].Value as TypeReference;
if (mixinInterfaceTypeReference == null)
{
throw new ArgumentException("Expected constructor argument to be a TypeReference", "weaveAttribute");
}
var mixinInterfaceType = mixinInterfaceTypeReference.Resolve();
if (!mixinInterfaceType.IsInterface)
{
weavingContext.LogError(string.Format("Configured mixin interface type is not an interface: [{0}]", mixinInterfaceType.FullName));
// let execution continue...an error will be thrown for this particular weave if invocation is attempted
}
var matchedMap = this.Config.InterfaceMixinMap.SingleOrDefault(
map => map.GetInterfaceType(weavingContext).FullName == mixinInterfaceType.FullName);
if(matchedMap == null)
{
weavingContext.LogWarning("Could not find the a configuration for the requested interface: " + mixinInterfaceType.FullName);
return;
}
new InterfaceMixinWeaver(mixinInterfaceType, matchedMap.GetMixinType(weavingContext), target).Execute();
}