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 #73 from LokiMidgard/ExternalDependency
External dependency
- Loading branch information
Showing
9 changed files
with
126 additions
and
2 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
...slyn.Tests.Generators.Dependency/CodeGeneration.Roslyn.Tests.Generators.Dependency.csproj
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,8 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netstandard1.6</TargetFramework> | ||
<PackageTargetFallback>$(PackageTargetFallback);portable-net45+win8+wp8+wpa81;</PackageTargetFallback> | ||
</PropertyGroup> | ||
|
||
</Project> |
9 changes: 9 additions & 0 deletions
9
src/CodeGeneration.Roslyn.Tests.Generators.Dependency/NameGenerator.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,9 @@ | ||
using System; | ||
|
||
namespace CodeGeneration.Roslyn.Tests.Generators.Dependency | ||
{ | ||
public class NameGenerator | ||
{ | ||
public static string Combine(string s1, string s2) => s1 + s2; | ||
} | ||
} |
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
24 changes: 24 additions & 0 deletions
24
src/CodeGeneration.Roslyn.Tests.Generators/ExternalDuplicateWithSuffixByNameAttribute.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,24 @@ | ||
// 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.Method, Inherited = false, AllowMultiple = true)] | ||
[CodeGenerationAttribute("CodeGeneration.Roslyn.Tests.Generators.ExternalDuplicateWithSuffixGenerator, CodeGeneration.Roslyn.Tests.Generators, Version=" + ThisAssembly.AssemblyVersion + ", Culture=neutral, PublicKeyToken=null")] | ||
[Conditional("CodeGeneration")] | ||
public class ExternalDuplicateWithSuffixByNameAttribute : Attribute | ||
{ | ||
public ExternalDuplicateWithSuffixByNameAttribute(string suffix) | ||
{ | ||
Requires.NotNullOrEmpty(suffix, nameof(suffix)); | ||
|
||
this.Suffix = suffix; | ||
} | ||
|
||
public string Suffix { get; } | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
src/CodeGeneration.Roslyn.Tests.Generators/ExternalDuplicateWithSuffixGenerator.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,54 @@ | ||
// 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.Collections.Generic; | ||
using System.Collections.Immutable; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using CodeGeneration.Roslyn.Tests.Generators.Dependency; | ||
using Microsoft.CodeAnalysis; | ||
using Microsoft.CodeAnalysis.CSharp; | ||
using Microsoft.CodeAnalysis.CSharp.Syntax; | ||
using Validation; | ||
|
||
public class ExternalDuplicateWithSuffixGenerator : ICodeGenerator | ||
{ | ||
private readonly AttributeData attributeData; | ||
private readonly ImmutableDictionary<string, TypedConstant> data; | ||
private readonly string suffix; | ||
|
||
public ExternalDuplicateWithSuffixGenerator(AttributeData attributeData) | ||
{ | ||
Requires.NotNull(attributeData, nameof(attributeData)); | ||
|
||
this.suffix = (string)attributeData.ConstructorArguments[0].Value; | ||
this.attributeData = attributeData; | ||
this.data = this.attributeData.NamedArguments.ToImmutableDictionary(kv => kv.Key, kv => kv.Value); | ||
} | ||
|
||
public Task<SyntaxList<MemberDeclarationSyntax>> GenerateAsync(TransformationContext context, IProgress<Diagnostic> progress, CancellationToken cancellationToken) | ||
{ | ||
var results = SyntaxFactory.List<MemberDeclarationSyntax>(); | ||
|
||
MemberDeclarationSyntax copy = null; | ||
var applyToClass = context.ProcessingNode as MethodDeclarationSyntax; | ||
if (applyToClass != null) | ||
{ | ||
copy = applyToClass | ||
.WithIdentifier(SyntaxFactory.Identifier(NameGenerator.Combine(applyToClass.Identifier.ValueText, this.suffix))); | ||
} | ||
|
||
if (copy != null) | ||
{ | ||
results = results.Add(copy); | ||
} | ||
|
||
return Task.FromResult(results); | ||
} | ||
} | ||
} |
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