Cilador.Fody.InterfaceMixins.InterfaceMixinWeaver.InterfaceMixinWeaver C# (CSharp) Method

InterfaceMixinWeaver() public method

Creates a new InterfaceMixinWeaver.
/// Thrown if is not an interface, if implements /// does not implement , or if implements any interface /// other than . ///
public InterfaceMixinWeaver ( Mono.Cecil.TypeDefinition interfaceType, Mono.Cecil.TypeDefinition mixinType, Mono.Cecil.TypeDefinition target ) : System
interfaceType Mono.Cecil.TypeDefinition Interface which will be added to the .
mixinType Mono.Cecil.TypeDefinition Type whose implementation will be cloned into the .
target Mono.Cecil.TypeDefinition Type which will be modified by this command invocation.
return System
        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;
        }