Cilador.Fody.InterfaceMixins.InterfaceMixinWeave.Weave C# (CSharp) Method

Weave() public method

Applies the weave to a target type.
/// The is not of type , or it does not /// contain the expected argument values. ///
public Weave ( IWeavingContext weavingContext, Mono.Cecil.TypeDefinition target, CustomAttribute weaveAttribute ) : void
weavingContext IWeavingContext Context data for weaving.
target Mono.Cecil.TypeDefinition The type to which the weave will be applied/
weaveAttribute Mono.Cecil.CustomAttribute Attribute that may contain arguments for the weave invocation. This must be of type .
return void
        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();
        }
InterfaceMixinWeave