Skip to content
This repository was archived by the owner on Dec 12, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// 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;

[AttributeUsage(AttributeTargets.All, Inherited = false)]
[CodeGenerationAttribute(typeof(EmptyPartialGenerator))]
[Conditional("CodeGeneration")]
public class EmptyPartialAttribute : Attribute
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// 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;

public class EmptyPartialGenerator : ICodeGenerator
{

public EmptyPartialGenerator(AttributeData attributeData)
{
}

public Task<SyntaxList<MemberDeclarationSyntax>> GenerateAsync(TransformationContext context, IProgress<Diagnostic> progress, CancellationToken cancellationToken)
{
if (!(context.ProcessingNode is TypeDeclarationSyntax typeDeclaration))
{
return Task.FromResult(SyntaxFactory.List<MemberDeclarationSyntax>());
}

var partial = typeDeclaration is StructDeclarationSyntax structDeclaration
? StructPartial(structDeclaration)
: ClassPartial((ClassDeclarationSyntax) typeDeclaration);
var results = SyntaxFactory.SingletonList(partial);
return Task.FromResult(results);
}

private static MemberDeclarationSyntax ClassPartial(ClassDeclarationSyntax declaration)
{
return SyntaxFactory.ClassDeclaration(declaration.Identifier)
.WithTypeParameterList(declaration.TypeParameterList)
.WithModifiers(SyntaxTokenList.Create(SyntaxFactory.Token(SyntaxKind.PartialKeyword)));
}

private static MemberDeclarationSyntax StructPartial(StructDeclarationSyntax declaration)
{
return SyntaxFactory.StructDeclaration(declaration.Identifier)
.WithTypeParameterList(declaration.TypeParameterList)
.WithModifiers(SyntaxTokenList.Create(SyntaxFactory.Token(SyntaxKind.PartialKeyword)));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="2.2.0" />
<PackageReference Include="Microsoft.CSharp" Version="4.4.1" />
<PackageReference Include="Xunit" Version="2.3.1" />
<PackageReference Include="Xunit.runner.visualstudio" Version="2.3.1" />
Expand Down
Loading