Skip to content

Commit 9ade2e8

Browse files
authored
Merge pull request #15 from ful-stackz/feat/use-roslyn-for-code-generation
Use Roslyn backend for code generation
2 parents 3c58527 + 25618d4 commit 9ade2e8

14 files changed

Lines changed: 531 additions & 347 deletions

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
- Introspection API via the new .HasMember() method, available on applicable structure builders
1313
- More null arguments sanitizing in public methods and consecutively more `ArgumentNullException` and `ArgumentException`, which are documented in the respective methods
14+
- Using Roslyn APIs to generate the source code via an actual AST, rather than string templates hydration
1415

1516
### Changed
1617

18+
- **[breaking]** `.ToSourceCode(bool)` has been changed to `.ToSourceCode()`; all generated code is now formatted by default
1719
- Refactored the internal structures from `class` to `readonly struct`
1820
- Made better use of optionals and replaced some nullables
21+
- Enums no longer have a trailing comma
22+
23+
### Fixed
24+
25+
- Fixes the issue described in [PR#13](https://github.com/ful-stackz/SharpCode/pull/13) - source code template strings were breaking when hydration keywords were used by consumer code
1926

2027
## [0.2.0] - 2020-10-05
2128

src/SharpCode.Test/ClassBuilderTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class ClassBuilderTests
1111
public void CreateClass_WithNoMembers_Works()
1212
{
1313
var generatedCode = Code.CreateClass("User")
14-
.ToSourceCode(formatted: true)
14+
.ToSourceCode()
1515
.WithUnixEOL();
1616

1717
var expectedCode = @"
@@ -28,7 +28,7 @@ public void CreateClass_WithSummary_Works()
2828
{
2929
var generatedCode = Code.CreateClass("User")
3030
.WithSummary("A user of the application")
31-
.ToSourceCode(formatted: true)
31+
.ToSourceCode()
3232
.WithUnixEOL();
3333

3434
var expectedCode = @"
@@ -50,7 +50,7 @@ public void CreateClass_WithFields()
5050
.WithField(Code.CreateField("int", "_hypotenuse"))
5151
.WithField(Code.CreateField("double", "_adjacent"))
5252
.WithField(Code.CreateField("float", "_opposite"))
53-
.ToSourceCode(formatted: true)
53+
.ToSourceCode()
5454
.WithUnixEOL();
5555

5656
var expectedCode = @"

src/SharpCode.Test/EnumBuilderTests.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ internal enum UserStatus
2727
Inactive,
2828
Active,
2929
Blocked,
30-
NotConfirmed,
30+
NotConfirmed
3131
}
3232
".Trim().WithUnixEOL();
3333

@@ -58,7 +58,7 @@ private enum UserStatus
5858
Inactive,
5959
Active,
6060
Blocked,
61-
NotConfirmed,
61+
NotConfirmed
6262
}
6363
".Trim().WithUnixEOL();
6464

@@ -89,7 +89,7 @@ internal enum UserStatus
8989
/// Like, all the time
9090
/// </summary>
9191
Active,
92-
Asleep,
92+
Asleep
9393
}
9494
".Trim().WithUnixEOL();
9595

@@ -126,7 +126,7 @@ internal enum UserStatus
126126
/// Like, all the time
127127
/// </summary>
128128
Active,
129-
Asleep,
129+
Asleep
130130
}
131131
".Trim().WithUnixEOL();
132132

@@ -157,7 +157,7 @@ public enum Colors
157157
Green = 1,
158158
Blue = 2,
159159
Orange = 4,
160-
Black = 8,
160+
Black = 8
161161
}
162162
".Trim().WithUnixEOL();
163163

@@ -181,7 +181,7 @@ public enum Color
181181
None = 0,
182182
Red = 100,
183183
Green = 222,
184-
Blue = 404,
184+
Blue = 404
185185
}
186186
".Trim().WithUnixEOL();
187187

@@ -209,7 +209,7 @@ public enum Storage
209209
HardDrive = 1,
210210
SolidStateDrive = 2,
211211
FlashStick,
212-
ExternalHardDrive = 4,
212+
ExternalHardDrive = 4
213213
}
214214
".Trim().WithUnixEOL();
215215

src/SharpCode.Test/NamespaceBuilderTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ public enum Level
179179
{
180180
Low,
181181
Medium,
182-
High,
182+
High
183183
}
184184
}
185185
".Trim().WithUnixEOL();
@@ -216,7 +216,7 @@ public enum Level
216216
Medium = 4,
217217
High = 8,
218218
ExtraHigh = 16,
219-
Max = 32,
219+
Max = 32
220220
}
221221
}
222222
".Trim().WithUnixEOL();

0 commit comments

Comments
 (0)