Skip to content

Source Generator #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 27 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
a67a86a
added the first draft for source generators
Guiorgy Feb 25, 2024
066bd87
error out if neither FindAndReplaces nor RegexReplaces is set
Guiorgy Feb 25, 2024
c1e60fc
fixed typo (missed plural s)
Guiorgy Feb 25, 2024
4ce158e
remove GenerateCopy attribute in the copied source
Guiorgy Feb 25, 2024
a11aa10
include leading trivia (doc comments)
Guiorgy Feb 25, 2024
d515de6
moved GenerateSource method below SyntaxProviderTransform
Guiorgy Feb 25, 2024
4fd0d77
moved ReportDiagnostic method below SyntaxProviderTransform
Guiorgy Feb 25, 2024
996bc90
fixed namespace reversed
Guiorgy Feb 25, 2024
1677140
generate the copy source file
Guiorgy Feb 25, 2024
f69cafa
only target .NET 8 when building DebugGenerators
Guiorgy Feb 25, 2024
f912cb4
put assertion inside #if DEBUGGENERATORS
Guiorgy Feb 25, 2024
63a57b8
remove SourceGenerators namespace from the copy
Guiorgy Feb 25, 2024
4b661ae
removed Carriage Return (\r) character at the end of comment lines
Guiorgy Feb 25, 2024
b988032
perform replacements on namespace and declarations
Guiorgy Feb 26, 2024
82f7e70
error out if parent is not declared as partial
Guiorgy Feb 26, 2024
82c6826
fixed wrong condition
Guiorgy Feb 26, 2024
931b9f6
disable namespace replacement for now
Guiorgy Feb 26, 2024
82cc4df
added Span Trim and IsWhiteSpace extensions
Guiorgy Feb 26, 2024
c468483
allow multiple uses of the attribute
Guiorgy Feb 26, 2024
4b718bf
added GeneratedFileTag to the attribute
Guiorgy Feb 26, 2024
b57120c
use file name as GeneratedFileTag by default if target is partial
Guiorgy Feb 26, 2024
6e270a5
make the GenerateCopy attribute internal
Guiorgy Feb 26, 2024
cecf122
fixed doc comments for Span.Trim
Guiorgy Feb 27, 2024
aa7ff10
also check target class for partial
Guiorgy Feb 27, 2024
38f6383
removed incorrectly pushed temporary file
Guiorgy Feb 27, 2024
b2f0151
reformatted the GetAttributeSyntax method
Guiorgy Mar 18, 2024
87bb008
calculate hash codes inside unchecked blocks
Guiorgy Mar 18, 2024
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
11 changes: 11 additions & 0 deletions SpanExtensions.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,27 @@ VisualStudioVersion = 17.5.33627.172
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SpanExtensions", "src\SpanExtensions.csproj", "{75DE5AFD-663E-415D-9B95-6BC513BD4A07}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SourceGenerators", "src\SourceGenerators\SourceGenerators.csproj", "{F21A6902-D205-4127-8DF4-49B5548BF28F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
DebugGenerators|Any CPU = DebugGenerators|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{75DE5AFD-663E-415D-9B95-6BC513BD4A07}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{75DE5AFD-663E-415D-9B95-6BC513BD4A07}.Debug|Any CPU.Build.0 = Debug|Any CPU
{75DE5AFD-663E-415D-9B95-6BC513BD4A07}.DebugGenerators|Any CPU.ActiveCfg = DebugGenerators|Any CPU
{75DE5AFD-663E-415D-9B95-6BC513BD4A07}.DebugGenerators|Any CPU.Build.0 = DebugGenerators|Any CPU
{75DE5AFD-663E-415D-9B95-6BC513BD4A07}.Release|Any CPU.ActiveCfg = Release|Any CPU
{75DE5AFD-663E-415D-9B95-6BC513BD4A07}.Release|Any CPU.Build.0 = Release|Any CPU
{F21A6902-D205-4127-8DF4-49B5548BF28F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F21A6902-D205-4127-8DF4-49B5548BF28F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F21A6902-D205-4127-8DF4-49B5548BF28F}.DebugGenerators|Any CPU.ActiveCfg = DebugGenerators|Any CPU
{F21A6902-D205-4127-8DF4-49B5548BF28F}.DebugGenerators|Any CPU.Build.0 = DebugGenerators|Any CPU
{F21A6902-D205-4127-8DF4-49B5548BF28F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F21A6902-D205-4127-8DF4-49B5548BF28F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
41 changes: 41 additions & 0 deletions src/InternalExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System;


namespace SpanExtensions
{
static class InternalExtensions
{
/// <summary>
/// Indicates whether the specified span contains only white-space characters.
/// </summary>
/// <param name="span">The source span.</param>
/// <returns><see langword="true"/> if the span contains only whitespace characters, <see langword="false"/> otherwise.</returns>
public static bool IsWhiteSpace(this Span<char> span)
{
return ((ReadOnlySpan<char>)span).IsWhiteSpace();
}

#if !NETCOREAPP3_0_OR_GREATER
/// <summary>
/// Removes all leading and trailing white-space characters from the span.
/// </summary>
/// <param name="span">The source span from which the characters are removed.</param>
/// <returns>The trimmed character span.</returns>
public static Span<char> Trim(this Span<char> span)
{
ReadOnlySpan<char> rospan = span;
ReadOnlySpan<char> leftTrimmed = rospan.TrimStart();
ReadOnlySpan<char> trimmed = rospan.TrimEnd();

if(span.Length == trimmed.Length)
{
return span;
}
else
{
return span.Slice(rospan.Length - leftTrimmed.Length, trimmed.Length);
}
}
#endif
}
}
Loading