示例#1
0
        protected override AttributeProviderAttributeArgument[] GetAttributeArguments(IProcessableComponent component, Type attr)
        {
            var typeDefinition = component.Type == ProcessableComponentType.Type ? ((TypeDefinition)component.UnderlyingComponent) : null;

            if (component.Name.StartsWith(AddAttributeProcessorTests.InjectAttribute1Prefix))
            {
                return(new AttributeProviderAttributeArgument[]
                {
                    AttributeProviderAttributeArgument.CreateParameterArgument("component", component.Type),
                    AttributeProviderAttributeArgument.CreateParameterArgument("type", typeDefinition),
                    AttributeProviderAttributeArgument.CreateParameterArgument("nameHash", component.Name.GetHashCode()),
                    AttributeProviderAttributeArgument.CreateParameterArgument("name", component.Name)
                });
            }
            else if (component.Name.StartsWith(AddAttributeProcessorTests.InjectAttribute2Prefix))
            {
                return(new AttributeProviderAttributeArgument[]
                {
                    AttributeProviderAttributeArgument.CreateParameterArgument("component", new Enum[] { component.Type, component.Type, component.Type }),
                    AttributeProviderAttributeArgument.CreateParameterArgument("type", new TypeReference[] { typeDefinition, typeDefinition, typeDefinition }),
                    AttributeProviderAttributeArgument.CreateParameterArgument("nameHash", new int[] { component.Name.GetHashCode(), component.Name.GetHashCode(), component.Name.GetHashCode() }),
                    AttributeProviderAttributeArgument.CreateParameterArgument("name", new string[] { component.Name, component.Name, component.Name })
                });
            }
            else
            {
                throw new InvalidOperationException();
            }
        }
示例#2
0
 protected override AttributeProviderAttributeArgument[] GetAttributeArguments(IProcessableComponent component, Type att)
 {
     return(new AttributeProviderAttributeArgument[]
     {
         AttributeProviderAttributeArgument.CreateParameterArgument("text", $"hello from '{component.Name}'!")
     });
 }
示例#3
0
        protected override AttributeProviderAttributeArgument[] GetAttributeArguments(IProcessableComponent component, Type attr)
        {
            var typeDefinition = component.Type == ProcessableComponentType.Type ? ((TypeDefinition)component.UnderlyingComponent) : null;

            if (attr.Name.Equals(typeof(ExceptionRaiseSiteAttribute).Name))
            {
                return(new AttributeProviderAttributeArgument[]
                {
                    AttributeProviderAttributeArgument.CreateParameterArgument("name", CurrentAttributeArguments[0].ToString()),
                    AttributeProviderAttributeArgument.CreateParameterArgument("target", CurrentAttributeArguments[1].ToString())
                });
            }
            else if (attr.Name.Equals(typeof(ExceptionChannelAttribute).Name))
            {
                return(new AttributeProviderAttributeArgument[]
                {
                    AttributeProviderAttributeArgument.CreateParameterArgument("name", CurrentAttributeArguments[0].ToString()),
                    AttributeProviderAttributeArgument.CreateParameterArgument("exception", CurrentAttributeArguments[1].ToString()),
                    AttributeProviderAttributeArgument.CreateParameterArgument("raiseSite", CurrentAttributeArguments[2].ToString())
                });
            }
            else if (attr.Name.Equals(typeof(ExceptionHandlerAttribute).Name))
            {
                return(new AttributeProviderAttributeArgument[]
                {
                    AttributeProviderAttributeArgument.CreateParameterArgument("channel", CurrentAttributeArguments[0].ToString()),
                    AttributeProviderAttributeArgument.CreateParameterArgument("target", CurrentAttributeArguments[1].ToString()),
                    AttributeProviderAttributeArgument.CreateParameterArgument("exception", CurrentAttributeArguments[2].ToString()),
                    AttributeProviderAttributeArgument.CreateParameterArgument("methodName", CurrentAttributeArguments[3].ToString()),
                });
            }
            else if (attr.Name.Equals(typeof(ExceptionInterfaceAttribute).Name))
            {
                return(new AttributeProviderAttributeArgument[]
                {
                    AttributeProviderAttributeArgument.CreateParameterArgument("name", CurrentAttributeArguments[0].ToString()),
                    AttributeProviderAttributeArgument.CreateParameterArgument("target", CurrentAttributeArguments[1].ToString())
                });
            }
            else
            {
                throw new ArgumentException();
            }
        }