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); }
public static string ExtractArgumentFromAttribute(this AttributeArgumentSyntax arg) { return(arg.Expression switch { LiteralExpressionSyntax les when les.Kind() == SyntaxKind.StringLiteralExpression => les.Token.ValueText, _ => arg.ToString() });
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); }
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); }
public override void VisitAttributeArgument(AttributeArgumentSyntax node) { Debug.Fail(node.ToString()); base.VisitAttributeArgument(node); }
public static string GetGuidMetadataValue(this AttributeArgumentSyntax syntax) { return(syntax?.ToString().Replace("\"", "")); }