public CompilationUnitSyntax Enrich(CompilationUnitSyntax syntax) => syntax .AddAttributeLists( SyntaxFactory.AttributeList().AddAttributes( SyntaxFactory.Attribute(SyntaxFactory.ParseName("System.Runtime.Versioning.TargetFramework")) .AddArgumentListArguments( SyntaxFactory.AttributeArgument(SyntaxHelpers.StringLiteral(".NETStandard,Version=v2.0")), SyntaxFactory.AttributeArgument(SyntaxHelpers.StringLiteral("")) .WithNameEquals(SyntaxFactory.NameEquals("FrameworkDisplayName")))) .WithTarget(SyntaxFactory.AttributeTargetSpecifier(SyntaxFactory.Token(SyntaxKind.AssemblyKeyword))));
public static Task <Document> RefactorAsync(Document document, CompilationUnitSyntax compilationUnitSyntax, CancellationToken cancellationToken = default) { var attributeList = GetGenerator(document) .InternalVisibleToDynamicProxyAttributeList() .Cast <AttributeListSyntax>() .WithTarget(AttributeTargetSpecifier( Token(SyntaxKind.AssemblyKeyword))); var updatedCompilationUnitSyntax = compilationUnitSyntax.AddAttributeLists(attributeList); return(document.ReplaceNodeAsync(compilationUnitSyntax, updatedCompilationUnitSyntax, cancellationToken)); }
public CompilationUnitSyntax Enrich(CompilationUnitSyntax target) => target.AddAttributeLists( SyntaxFactory.AttributeList().AddAttributes( SyntaxFactory.Attribute(SyntaxFactory.ParseName("System.Reflection.AssemblyVersion")) .AddArgumentListArguments(SyntaxFactory.AttributeArgument( SyntaxHelpers.StringLiteral(_settings.Version.ToString())))) .WithTarget(SyntaxFactory.AttributeTargetSpecifier(SyntaxFactory.Token(SyntaxKind.AssemblyKeyword))), SyntaxFactory.AttributeList().AddAttributes( SyntaxFactory.Attribute(SyntaxFactory.ParseName("System.Reflection.AssemblyFileVersion")) .AddArgumentListArguments(SyntaxFactory.AttributeArgument( SyntaxHelpers.StringLiteral(_settings.Version.ToString())))) .WithTarget(SyntaxFactory.AttributeTargetSpecifier(SyntaxFactory.Token(SyntaxKind.AssemblyKeyword))), SyntaxFactory.AttributeList().AddAttributes( SyntaxFactory.Attribute(SyntaxFactory.ParseName("System.Reflection.AssemblyInformationalVersion")) .AddArgumentListArguments(SyntaxFactory.AttributeArgument( SyntaxHelpers.StringLiteral(_settings.Version.ToString() + (_settings.VersionSuffix ?? ""))))) .WithTarget(SyntaxFactory.AttributeTargetSpecifier(SyntaxFactory.Token(SyntaxKind.AssemblyKeyword))));
public override TDeclarationNode AddAttributes <TDeclarationNode>( TDeclarationNode destination, IEnumerable <AttributeData> attributes, SyntaxToken?target, CodeGenerationOptions options, CancellationToken cancellationToken) { if (target.HasValue && !target.Value.IsValidAttributeTarget()) { throw new ArgumentException("target"); } var attributeSyntaxList = AttributeGenerator.GenerateAttributeLists(attributes.ToImmutableArray(), options, target).ToArray(); return(destination switch { MemberDeclarationSyntax member => Cast <TDeclarationNode>(member.AddAttributeLists(attributeSyntaxList)), AccessorDeclarationSyntax accessor => Cast <TDeclarationNode>(accessor.AddAttributeLists(attributeSyntaxList)), CompilationUnitSyntax compilationUnit => Cast <TDeclarationNode>(compilationUnit.AddAttributeLists(attributeSyntaxList)), ParameterSyntax parameter => Cast <TDeclarationNode>(parameter.AddAttributeLists(attributeSyntaxList)), TypeParameterSyntax typeParameter => Cast <TDeclarationNode>(typeParameter.AddAttributeLists(attributeSyntaxList)), _ => destination, });
public static Task <Document> RefactorAsync(Document document, CompilationUnitSyntax compilationUnitSyntax, CancellationToken cancellationToken = default) { var addAttributeLists = compilationUnitSyntax.AddAttributeLists( AttributeList( AttributeTargetSpecifier( Token(SyntaxKind.AssemblyKeyword)), SingletonSeparatedList( Attribute( QualifiedName( QualifiedName( QualifiedName( IdentifierName("System"), IdentifierName("Runtime")), IdentifierName("CompilerServices")), IdentifierName("InternalsVisibleTo")), AttributeArgumentList( SingletonSeparatedList( AttributeArgument( LiteralExpression( SyntaxKind.StringLiteralExpression, Literal("DynamicProxyGenAssembly2"))))))))); return(document.ReplaceNodeAsync(compilationUnitSyntax, addAttributeLists, CancellationToken.None)); }
public static SyntaxNode PatchAttributes(this CompilationUnitSyntax unit, IEnumerable <SyntaxNode> nodes) => unit.AddAttributeLists(nodes.OfType <AttributeListSyntax>().ToArray());