/// <summary> /// Applies the weave to a target type. /// </summary> /// <param name="weavingContext">Context data for weaving.</param> /// <param name="target">The type to which the weave will be applied/</param> /// <param name="weaveAttribute">Attribute that may contain arguments for the weave invocation. This must be of type <see cref="InterfaceMixinAttribute"/>.</param> /// <exception cref="ArgumentException"> /// The <paramref name="weaveAttribute"/> is not of type <see cref="InterfaceMixinAttribute"/>, or it does not /// contain the expected argument values. /// </exception> 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(); }
/// <summary> /// Applies the weave to a target type. /// </summary> /// <param name="weavingContext">Context data for weaving.</param> /// <param name="target">The type to which the weave will be applied/</param> /// <param name="weaveAttribute">Attribute that may contain arguments for the weave invocation. This must be of type <see cref="InterfaceMixinAttribute"/>.</param> /// <exception cref="ArgumentException"> /// The <paramref name="weaveAttribute"/> is not of type <see cref="InterfaceMixinAttribute"/>, or it does not /// contain the expected argument values. /// </exception> 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(); }
/// <summary> /// Gets the mixin implementation type. /// </summary> /// <param name="weavingContext">Context to use for resolving the type.</param> /// <returns>Resolved mixin definition type.</returns> public TypeDefinition GetMixinType(IWeavingContext weavingContext) { Contract.Requires(weavingContext != null); return(weavingContext.GetTypeDefinition(this.Mixin)); }
/// <summary> /// Gets the mixin definition interface. /// </summary> /// <param name="weavingContext">Context to use for resolving the type.</param> /// <returns>Resolved mixin definition interface type.</returns> public TypeDefinition GetInterfaceType(IWeavingContext weavingContext) { Contract.Requires(weavingContext != null); return(weavingContext.GetTypeDefinition(this.Interface)); }
/// <summary> /// Gets the mixin implementation type. /// </summary> /// <param name="weavingContext">Context to use for resolving the type.</param> /// <returns>Resolved mixin definition type.</returns> public TypeDefinition GetMixinType(IWeavingContext weavingContext) { Contract.Requires(weavingContext != null); return weavingContext.GetTypeDefinition(this.Mixin); }
/// <summary> /// Gets the mixin definition interface. /// </summary> /// <param name="weavingContext">Context to use for resolving the type.</param> /// <returns>Resolved mixin definition interface type.</returns> public TypeDefinition GetInterfaceType(IWeavingContext weavingContext) { Contract.Requires(weavingContext != null); return weavingContext.GetTypeDefinition(this.Interface); }