Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>
<PropertyGroup>
<Version>8.27.0</Version>
<Version>8.28.0</Version>
<LangVersion>13.0</LangVersion>
<Authors>Jeremy D. Miller;Babu Annamalai;Jaedyn Tonee</Authors>
<PackageIconUrl>https://martendb.io/logo.png</PackageIconUrl>
Expand Down
6 changes: 4 additions & 2 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@
<PackageVersion Include="FluentAssertions" Version="6.12.0" />
<PackageVersion Include="FSharp.Core" Version="9.0.100" />
<PackageVersion Include="FSharp.SystemTextJson" Version="1.3.13" />
<PackageVersion Include="JasperFx" Version="1.21.5" />
<PackageVersion Include="JasperFx.Events" Version="1.24.2" />
<PackageVersion Include="JasperFx" Version="1.23.0" />
<PackageVersion Include="JasperFx.Events" Version="1.25.0" />
<PackageVersion Include="JasperFx.Events.SourceGenerator" Version="1.4.0" />
<PackageVersion Include="JasperFx.RuntimeCompiler" Version="4.4.0" />
<PackageVersion Include="Jil" Version="3.0.0-alpha2" />
<PackageVersion Include="Lamar" Version="7.1.1" />
<PackageVersion Include="Lamar.Microsoft.DependencyInjection" Version="15.0.0" />
<PackageVersion Include="Marten" Version="8.2.1" />
<PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.8.0" />
<PackageVersion Include="Meziantou.Analyzer" Version="2.0.257" />
<PackageVersion Include="Microsoft.AspNetCore.OData" Version="8.2.5" />
<PackageVersion Include="Microsoft.AspNetCore.SignalR" Version="1.1.0" />
Expand Down
64 changes: 64 additions & 0 deletions src/Marten.SourceGeneration/DiscoveredMartenTypesEmitter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using System.Collections.Generic;
using System.Text;

namespace Marten.SourceGeneration;

/// <summary>
/// Emits the DiscoveredMartenTypes static manifest class containing
/// compile-time discovered document, projection, and event types.
/// </summary>
internal static class DiscoveredMartenTypesEmitter
{
public static string Emit(
List<string> documentTypes,
List<string> projectionTypes,
List<string> eventTypes)
{
var sb = new StringBuilder();

sb.AppendLine("// <auto-generated />");
sb.AppendLine("// This file is generated by Marten.SourceGeneration.");
sb.AppendLine("// Do not edit manually.");
sb.AppendLine("#nullable enable");
sb.AppendLine();
sb.AppendLine("using System;");
sb.AppendLine("using System.Collections.Generic;");
sb.AppendLine();
sb.AppendLine("namespace Marten.Generated;");
sb.AppendLine();
sb.AppendLine("/// <summary>");
sb.AppendLine("/// Compile-time discovered Marten types. Used by StoreOptions to bypass");
sb.AppendLine("/// runtime assembly scanning when source generation is opted into.");
sb.AppendLine("/// </summary>");
sb.AppendLine("public static class DiscoveredMartenTypes");
sb.AppendLine("{");

// Document types
EmitTypeArray(sb, "DocumentTypes", documentTypes);
sb.AppendLine();

// Projection types
EmitTypeArray(sb, "ProjectionTypes", projectionTypes);
sb.AppendLine();

// Event types
EmitTypeArray(sb, "EventTypes", eventTypes);

sb.AppendLine("}");

return sb.ToString();
}

private static void EmitTypeArray(StringBuilder sb, string propertyName, List<string> types)
{
sb.AppendLine($" public static IReadOnlyList<Type> {propertyName} => new Type[]");
sb.AppendLine(" {");

foreach (var type in types)
{
sb.AppendLine($" typeof({type}),");
}

sb.AppendLine(" };");
}
}
24 changes: 24 additions & 0 deletions src/Marten.SourceGeneration/Marten.SourceGeneration.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Description>Source Generator for Marten document and projection type discovery</Description>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<LangVersion>12</LangVersion>
<Nullable>enable</Nullable>
<ImplicitUsings>false</ImplicitUsings>
<NoWarn>$(NoWarn);CS8603;CS8602;CS8604</NoWarn>
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
<IsRoslynComponent>true</IsRoslynComponent>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" PrivateAssets="all" />
</ItemGroup>

<!-- Source generators must not pull in the global Directory.Build.props TargetFramework -->
<PropertyGroup>
<GenerateDocumentationFile>false</GenerateDocumentationFile>
</PropertyGroup>

</Project>
Loading
Loading