Skip to content

Commit 42b8602

Browse files
committed
Splitted monolithic code to generators and processors & created a single multi taget AutoGraphSharp Project
1 parent 5ac44f6 commit 42b8602

21 files changed

+521
-794
lines changed

AutoGraphSharp.Core/AutoGraphGenerator.cs

Lines changed: 0 additions & 379 deletions
This file was deleted.

AutoGraphSharp.Core/AutoGraphSharp.Core.csproj

Lines changed: 0 additions & 13 deletions
This file was deleted.

AutoGraphSharp.Example/Program.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,9 @@ public static int Function(int a, int b)
1212
var c = (a + b *3 )/a;
1313

1414
if (a > b)
15-
{
1615
c = 1;
17-
}
1816
else
19-
{
2017
c = 2;
21-
}
2218

2319
return c;
2420
}

AutoGraphSharp.Test/AutoGraphSharp.Test.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
</ItemGroup>
2525

2626
<ItemGroup>
27-
<ProjectReference Include="..\AutoGraphSharp.Core\AutoGraphSharp.Core.csproj" />
27+
<ProjectReference Include="..\AutoGraphSharp\AutoGraphSharp.csproj" />
2828
</ItemGroup>
2929

3030
</Project>

AutoGraphSharp.sln

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@ VisualStudioVersion = 15.0.28010.2046
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutoGraphSharp.Test", "AutoGraphSharp.Test\AutoGraphSharp.Test.csproj", "{DDC59D66-427C-4752-A139-205336CE31ED}"
77
EndProject
8-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutoGraphSharp.Core", "AutoGraphSharp.Core\AutoGraphSharp.Core.csproj", "{1F6BB2BD-39AC-4041-8087-6DF30DE1694A}"
9-
EndProject
108
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutoGraphSharp.Example", "AutoGraphSharp.Example\AutoGraphSharp.Example.csproj", "{5109EBDB-5A45-4D9B-ABDF-6A521D6143CD}"
119
EndProject
12-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoGraphSharp", "AutoGraphSharp\AutoGraphSharp.csproj", "{C08B4694-8BAF-4A38-A124-B32211D43F09}"
10+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutoGraphSharp", "AutoGraphSharp\AutoGraphSharp.csproj", "{D3166113-33D7-47EE-A843-109C53021BFF}"
1311
EndProject
1412
Global
1513
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -21,18 +19,14 @@ Global
2119
{DDC59D66-427C-4752-A139-205336CE31ED}.Debug|Any CPU.Build.0 = Debug|Any CPU
2220
{DDC59D66-427C-4752-A139-205336CE31ED}.Release|Any CPU.ActiveCfg = Release|Any CPU
2321
{DDC59D66-427C-4752-A139-205336CE31ED}.Release|Any CPU.Build.0 = Release|Any CPU
24-
{1F6BB2BD-39AC-4041-8087-6DF30DE1694A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
25-
{1F6BB2BD-39AC-4041-8087-6DF30DE1694A}.Debug|Any CPU.Build.0 = Debug|Any CPU
26-
{1F6BB2BD-39AC-4041-8087-6DF30DE1694A}.Release|Any CPU.ActiveCfg = Release|Any CPU
27-
{1F6BB2BD-39AC-4041-8087-6DF30DE1694A}.Release|Any CPU.Build.0 = Release|Any CPU
2822
{5109EBDB-5A45-4D9B-ABDF-6A521D6143CD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
2923
{5109EBDB-5A45-4D9B-ABDF-6A521D6143CD}.Debug|Any CPU.Build.0 = Debug|Any CPU
3024
{5109EBDB-5A45-4D9B-ABDF-6A521D6143CD}.Release|Any CPU.ActiveCfg = Release|Any CPU
3125
{5109EBDB-5A45-4D9B-ABDF-6A521D6143CD}.Release|Any CPU.Build.0 = Release|Any CPU
32-
{C08B4694-8BAF-4A38-A124-B32211D43F09}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
33-
{C08B4694-8BAF-4A38-A124-B32211D43F09}.Debug|Any CPU.Build.0 = Debug|Any CPU
34-
{C08B4694-8BAF-4A38-A124-B32211D43F09}.Release|Any CPU.ActiveCfg = Release|Any CPU
35-
{C08B4694-8BAF-4A38-A124-B32211D43F09}.Release|Any CPU.Build.0 = Release|Any CPU
26+
{D3166113-33D7-47EE-A843-109C53021BFF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
27+
{D3166113-33D7-47EE-A843-109C53021BFF}.Debug|Any CPU.Build.0 = Debug|Any CPU
28+
{D3166113-33D7-47EE-A843-109C53021BFF}.Release|Any CPU.ActiveCfg = Release|Any CPU
29+
{D3166113-33D7-47EE-A843-109C53021BFF}.Release|Any CPU.Build.0 = Release|Any CPU
3630
EndGlobalSection
3731
GlobalSection(SolutionProperties) = preSolution
3832
HideSolutionNode = FALSE
File renamed without changes.

AutoGraphSharp/AutoGraphGenerator.cs

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
using AutoGraphSharp.CodeGeneration;
2+
using CodeGeneration.Roslyn;
3+
using Microsoft.CodeAnalysis;
4+
using Microsoft.CodeAnalysis.CSharp;
5+
using Microsoft.CodeAnalysis.CSharp.Syntax;
6+
using System;
7+
using System.Collections.Generic;
8+
using System.Linq;
9+
using System.Text;
10+
using System.Threading;
11+
using System.Threading.Tasks;
12+
using Validation;
13+
14+
namespace AutoGraphSharp
15+
{
16+
class AutoGraphGenerator : ICodeGenerator
17+
{
18+
private readonly Settings Settings;
19+
20+
public AutoGraphGenerator(AttributeData attributeData)
21+
{
22+
Requires.NotNull(attributeData, nameof(attributeData));
23+
24+
var prefix = "";
25+
var autoPrefix = "_";
26+
27+
if (attributeData.NamedArguments != null && attributeData.NamedArguments.Length > 0)
28+
{
29+
var prefixData = attributeData.NamedArguments.Where(e => e.Key == "Prefix").SingleOrDefault();
30+
var autoPrefixData = attributeData.NamedArguments.Where(e => e.Key == "AutoPrefix").SingleOrDefault();
31+
if (prefixData.Key != null)
32+
prefix = prefixData.Value.Value.ToString();
33+
34+
if (autoPrefixData.Key != null)
35+
autoPrefix = autoPrefixData.Value.Value.ToString();
36+
}
37+
38+
Settings = new Settings(prefix, autoPrefix);
39+
}
40+
41+
public Task<SyntaxList<MemberDeclarationSyntax>> GenerateAsync(
42+
TransformationContext context,
43+
IProgress<Diagnostic> progress,
44+
CancellationToken cancellationToken)
45+
{
46+
var results = SyntaxFactory.List<MemberDeclarationSyntax>();
47+
48+
//get the current method
49+
var method = (MethodDeclarationSyntax)context.ProcessingNode;
50+
//get the containing class
51+
var parentClass = (ClassDeclarationSyntax)context.ProcessingNode.Parent;
52+
53+
var autoMethod = new AutoMethodGenerator(Settings).Generate(method);
54+
var wrapperMethod = new WrapperMethodGenerator(Settings).Generate(method);
55+
56+
results = results.Add(wrapperMethod);
57+
results = results.Add(autoMethod);
58+
59+
return Task.FromResult(results);
60+
}
61+
}
62+
}

0 commit comments

Comments
 (0)