This repository has been archived by the owner on Dec 12, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #67 from Pzixel/feature/global_attributes_generation
Assembly attributes support
- Loading branch information
Showing
12 changed files
with
117 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/CodeGeneration.Roslyn.Tests.Generators/DirectoryPathAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright (c) Andrew Arnott. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information. | ||
|
||
namespace CodeGeneration.Roslyn.Tests.Generators | ||
{ | ||
using System; | ||
using System.Diagnostics; | ||
using Validation; | ||
|
||
[AttributeUsage(AttributeTargets.Assembly)] | ||
[CodeGenerationAttribute(typeof(DirectoryPathGenerator))] | ||
[Conditional("CodeGeneration")] | ||
public class DirectoryPathAttribute : Attribute | ||
{ | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
src/CodeGeneration.Roslyn.Tests.Generators/DirectoryPathGenerator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright (c) Andrew Arnott. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information. | ||
|
||
namespace CodeGeneration.Roslyn.Tests.Generators | ||
{ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.CodeAnalysis; | ||
using Microsoft.CodeAnalysis.CSharp; | ||
using Microsoft.CodeAnalysis.CSharp.Syntax; | ||
using Validation; | ||
using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory; | ||
|
||
public class DirectoryPathGenerator : ICodeGenerator | ||
{ | ||
public DirectoryPathGenerator(AttributeData attributeData) | ||
{ | ||
Requires.NotNull(attributeData, nameof(attributeData)); | ||
} | ||
|
||
public Task<SyntaxList<MemberDeclarationSyntax>> GenerateAsync(TransformationContext context, IProgress<Diagnostic> progress, CancellationToken cancellationToken) | ||
{ | ||
var member = ClassDeclaration("DirectoryPathTest") | ||
.AddMembers( | ||
FieldDeclaration( | ||
VariableDeclaration( | ||
PredefinedType(Token(SyntaxKind.StringKeyword))) | ||
.AddVariables( | ||
VariableDeclarator(Identifier("Path")) | ||
.WithInitializer( | ||
EqualsValueClause( | ||
LiteralExpression( | ||
SyntaxKind.StringLiteralExpression, | ||
Literal(context.ProjectDirectory)))))) | ||
.WithModifiers(TokenList(Token(SyntaxKind.PublicKeyword), Token(SyntaxKind.ConstKeyword)))); | ||
|
||
return Task.FromResult(List<MemberDeclarationSyntax>(new []{member})); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters