예제 #1
0
        private static Location GetSecurityAttributeActionSyntaxLocation(
            AttributeSyntax?nodeOpt,
            TypedConstant typedValue,
            out object displayString
            )
        {
            if (nodeOpt == null)
            {
                displayString = "";
                return(NoLocation.Singleton);
            }

            var argList = nodeOpt.ArgumentList;

            if (argList == null || argList.Arguments.IsEmpty())
            {
                // Optional SecurityAction parameter with default value.
                displayString = (FormattableString)$"{typedValue.ValueInternal}";
                return(nodeOpt.Location);
            }

            AttributeArgumentSyntax argSyntax = argList.Arguments[0];

            displayString = argSyntax.ToString();
            return(argSyntax.Location);
        }
예제 #2
0
 public static string ExtractArgumentFromAttribute(this AttributeArgumentSyntax arg)
 {
     return(arg.Expression switch
     {
         LiteralExpressionSyntax les when les.Kind() == SyntaxKind.StringLiteralExpression
         => les.Token.ValueText,
         _ => arg.ToString()
     });
예제 #3
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);
        }
예제 #4
0
        private static Location GetSecurityAttributeActionSyntaxLocation(AttributeSyntax nodeOpt, Cci.SecurityAction value, out string displayString)
        {
            if ((object)nodeOpt == null)
            {
                displayString = "";
                return(NoLocation.Singleton);
            }

            if (nodeOpt.ArgumentList.Arguments.IsEmpty())
            {
                // Optional SecurityAction parameter with default value.
                displayString = value.ToString();
                return(nodeOpt.Location);
            }

            AttributeArgumentSyntax argSyntax = nodeOpt.ArgumentList.Arguments[0];

            displayString = argSyntax.ToString();
            return(argSyntax.Location);
        }
예제 #5
0
 public override void VisitAttributeArgument(AttributeArgumentSyntax node)
 {
     Debug.Fail(node.ToString());
     base.VisitAttributeArgument(node);
 }
예제 #6
0
 public static string GetGuidMetadataValue(this AttributeArgumentSyntax syntax)
 {
     return(syntax?.ToString().Replace("\"", ""));
 }