public InterfaceMixinWeaver(TypeDefinition interfaceType, TypeDefinition mixinType, TypeDefinition target)
{
Contract.Requires(interfaceType != null);
Contract.Requires(mixinType != null);
Contract.Requires(target != null);
Contract.Requires(target.Module != null);
Contract.Requires(!target.IsValueType);
Contract.Requires(!target.IsPrimitive);
Contract.Ensures(this.InterfaceType != null);
Contract.Ensures(this.Target != null);
Contract.Ensures(this.Target.IsClass);
Contract.Ensures(this.Source != null);
if (!interfaceType.IsInterface)
{
throw new WeavingException(string.Format("Configured mixin definition interface type is not an interface: [{0}]", interfaceType.FullName));
}
if (mixinType.Interfaces.All(@interface => @interface.FullName != interfaceType.FullName))
{
throw new WeavingException(string.Format(
"Configured mixin implementation type [{0}] must implement the interface specified mixin interface definition [{1}]",
mixinType.FullName,
interfaceType.FullName));
}
if (mixinType.Interfaces.Count != 1)
{
throw new WeavingException(string.Format(
"Configured mixin implementation type [{0}] may implement only the mixin definition interface [{1}]",
mixinType.FullName,
interfaceType.FullName));
}
if (target.Interfaces.Any(@interface => @interface.Resolve().FullName == interfaceType.FullName))
{
throw new WeavingException(string.Format(
"Target type [{0}] already implements interface to be mixed [{1}]",
target.FullName,
interfaceType.FullName));
}
this.InterfaceType = interfaceType;
this.Source = mixinType;
this.Target = target;
}