Skip to content

Commit

Permalink
Add FastNew_PublicFastNew option
Browse files Browse the repository at this point in the history
  • Loading branch information
Nyrest committed Aug 14, 2024
1 parent 5a403ad commit c31c5e5
Show file tree
Hide file tree
Showing 16 changed files with 68 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public override CodeGenerationResult Generate(in GeneratorOptions options)
builder.WriteFileHeader();
builder.StartNamespace();
builder.Indent(1);
builder.AppendKeyword("public static partial class");
builder.AppendKeyword("static partial class");
builder.Append(ClassName);
builder.StartBlock(1);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public override CodeGenerationResult Generate(in GeneratorOptions options)
builder.WriteFileHeader();
builder.StartNamespace();
builder.Indent(1);
builder.AppendKeyword("public static partial class");
builder.AppendKeyword("static partial class");
builder.Append(ClassName);

builder.StartBlock(1);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
namespace FastGenericNew.SourceGenerator.CodeGenerators;

public class FastNewVisibilityGenerator : CodeGenerator<FastNewVisibilityGenerator>
{
public override string Filename => "FastNewVisibility.g.cs";

internal const string ClassName = "FastNew";

internal const string DelegateName = "FastNewDelegate";

public override CodeGenerationResult Generate(in GeneratorOptions options)
{
CodeBuilder builder = new(1024, in options);
builder.WriteFileHeader();
builder.StartNamespace();
builder.Indent(1);

builder.AppendKeyword(options.PublicFastNew ? "public" : "internal");

builder.AppendKeyword("static partial class");
builder.Append(ClassName);
builder.StartBlock(1);
builder.EndBlock(1);
builder.EndNamespace();

return builder.BuildAndDispose(this);
}

public override bool ShouldUpdate(in GeneratorOptions oldValue, in GeneratorOptions newValue) =>
base.ShouldUpdate(oldValue, newValue)
|| oldValue.PublicFastNew != newValue.PublicFastNew;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public override CodeGenerationResult Generate(in GeneratorOptions options)
builder.WriteFileHeader();
builder.StartNamespace();
builder.Indent(1);
builder.AppendKeyword("public static partial class");
builder.AppendKeyword("static partial class");
builder.Append(ClassName);

builder.StartBlock(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public override CodeGenerationResult Generate(in GeneratorOptions options)
builder.WriteFileHeader();
builder.StartNamespace();

builder.AppendKeyword("public static partial class");
builder.AppendKeyword("static partial class");
builder.Append(ClassName);

builder.StartBlock(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@
<CompilerVisibleProperty Include="FastNew_MultiThreadedGeneration" />
<CompilerVisibleProperty Include="FastNew_OutputGenerationInfo" />
<CompilerVisibleProperty Include="FastNew_AllowUnsafeImplementation" />
<CompilerVisibleProperty Include="FastNew_PublicFastNew" />
</ItemGroup>
</Project>
3 changes: 3 additions & 0 deletions src/FastGenericNew.SourceGenerator/GeneratorOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ public readonly partial record struct GeneratorOptions
[GeneratorOption(false, PresentPreProcessor = true)]
public bool AllowUnsafeImplementation { get; }

[GeneratorOption(false)]
public bool PublicFastNew { get; }

// ctor will be generated by InternalGenerator
//public GeneratorOptions(AnalyzerConfigOptionsProvider? provider)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ public GeneratorOptions(AnalyzerConfigOptionsProvider? provider)
MultiThreadedGeneration = options.GetOrDefault(nameof(MultiThreadedGeneration), true);
OutputGenerationInfo = options.GetOrDefault(nameof(OutputGenerationInfo), false);
AllowUnsafeImplementation = options.GetOrDefault(nameof(AllowUnsafeImplementation), false);
PublicFastNew = options.GetOrDefault(nameof(PublicFastNew), false);
}
}
1 change: 1 addition & 0 deletions src/FastGenericNew/FastGenericNew.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<FastNew_MultiThreadedGeneration>true</FastNew_MultiThreadedGeneration>
<FastNew_PrettyOutput>true</FastNew_PrettyOutput>
<FastNew_OutputGenerationInfo>true</FastNew_OutputGenerationInfo>
<FastNew_PublicFastNew>true</FastNew_PublicFastNew>
</PropertyGroup>

<!-- Nuget Package Properties-->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

namespace @FastGenericNew
{
public static partial class FastNew {
static partial class FastNew {

/// <summary>
/// <para>Create an instance of <typeparamref name="T" /></para>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

namespace @FastGenericNew
{
public static partial class FastNew {
static partial class FastNew {

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool TryCreateInstance<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

namespace @FastGenericNew
{
public static partial class FastNew {
static partial class FastNew {
public delegate T FastNewDelegate<
#if NET5_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by FastGenericNew.SourceGenerator
// Please do not modify this file directly
// <auto-generated/>
//------------------------------------------------------------------------------
#nullable enable
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using System.Reflection.Emit;
using System.ComponentModel;

namespace @FastGenericNew
{
public static partial class FastNew {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
// Please do not modify this file directly
// <auto-generated/>
//------------------------------------------------------------------------------
#define FastNewPX_AllowUnsafeImplementation
#nullable enable
using System;
using System.Collections.Generic;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

namespace @FastGenericNew
{
public static partial class FastNew {
static partial class FastNew {
public static Func<T> GetCreateInstance<
#if NET5_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
MultiThreadedGeneration = True
OutputGenerationInfo = True (default: False)
AllowUnsafeImplementation = False
PublicFastNew = True (default: False)
MSBuild Properties:
Expand All @@ -39,5 +40,6 @@
<FastNew_MultiThreadedGeneration>True<FastNew_MultiThreadedGeneration />
<FastNew_OutputGenerationInfo>True<FastNew_OutputGenerationInfo />
<FastNew_AllowUnsafeImplementation>False<FastNew_AllowUnsafeImplementation />
<FastNew_PublicFastNew>True<FastNew_PublicFastNew />
*/

0 comments on commit c31c5e5

Please sign in to comment.