示例#1
0
        public override SyntaxNode VisitAttributeArgument(AttributeArgumentSyntax node)
        {
            if (!node.IsKind(SyntaxKind.StringLiteralToken))
            {
                return(node);
            }

            var attributeSyntax = (AttributeSyntax)node.Parent.Parent;

            SyntaxNode result = node;

            var currentValue = node.ToString().Trim('"');

            switch (attributeSyntax.Name.ToString())
            {
            case "AssemblyVersion":
                if (_assemblyVersion == null)
                {
                    break;
                }

                result = node.WithExpression(SyntaxFactory.LiteralExpression(SyntaxKind.StringLiteralExpression,
                                                                             SyntaxFactory.Literal(VersionHelper.ProcessVersionString(currentValue, _assemblyVersion, "AssemblyVersion")
                                                                                                   )));

                break;

            case "AssemblyFileVersion":
                if (_assemblyFileVersion == null)
                {
                    break;
                }

                result = node.WithExpression(SyntaxFactory.LiteralExpression(SyntaxKind.StringLiteralExpression,
                                                                             SyntaxFactory.Literal(VersionHelper.ProcessVersionString(currentValue, _assemblyFileVersion, "AssemblyFileVersion")
                                                                                                   )));

                break;

            case "AssemblyInformationalVersion":
                if (_assemblyInformationalVersion != null)
                {
                    throw new NotImplementedException("Cannot patch AssemblyInformationalVersion yet.");
                }

                break;
            }

            return(result);
        }