private IWeave GetWeaverFor(TypeDefinition targetType, CustomAttribute weaveAttribute)
{
Contract.Requires(targetType != null);
Contract.Requires(weaveAttribute != null);
Contract.Ensures(Contract.Result<IWeave>() != null);
var weaveAttributeType = weaveAttribute.AttributeType.Resolve();
try
{
return this.Weaves.First(command =>
this.ModuleDefinition.Import(command.Metadata.AttributeType).Resolve() == weaveAttributeType &&
command.Value.IsInitialized).Value;
}
catch(Exception e)
{
throw new InvalidOperationException(
string.Format("Cannot find a configured weave for type [{0}] and weave attribute [{1}]", targetType.FullName, weaveAttributeType.FullName),
e);
}
}