Hardcoded.NET by Emanuele Onnivello
NuGet / site data
Details
Info
Name: Hardcoded.NET
Turn 'hardcoding' into a performance feature. Ironic, but accurate. It is a source generator that leverages Roslyn to convert resources into mapped constants.
Author: Emanuele Onnivello
NuGet: https://www.nuget.org/packages/Hardcoded.NET/
You can find more details at https://codeberg.org/wave/Hardcoded.NET
Author
Emanuele Onnivello

Original Readme
About
Generating compile-time SQL string constants from .sql files
How to use
Example (source csproj, source files)
- CSharp Project
- Program.cs
- PersonQueries.sql
This is the CSharp Project that references Hardcoded.NET
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Hardcoded.NET" Version="0.2.1">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<AdditionalFiles Include="PersonQueries.sql" />
</ItemGroup>
<PropertyGroup>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GX</CompilerGeneratedFilesOutputPath>
</PropertyGroup>
</Project>
This is the use of Hardcoded.NET in Program.cs
using HardcodedDemo;
Console.WriteLine(PersonQueries.GetPersonById);
This is the use of Hardcoded.NET in PersonQueries.sql
-- @hardcoded
-- @namespace HardcodedDemo
-- @class PersonQueries
-- @query GetPersonById
-- Retrieves a person by identifier
SELECT Id, Name
FROM Person
WHERE Id = @Id
Generated Files
Those are taken from $(BaseIntermediateOutputPath)\GX
- HardcodedDemo.PersonQueries.g.cs
namespace HardcodedDemo;
internal static partial class PersonQueries
{
/// <summary>
/// Retrieves a person by identifier
/// </summary>
internal const string GetPersonById = @"SELECT Id, Name
FROM Person
WHERE Id = @Id";
}
Useful
Download Example (.NET C#)
Share Hardcoded.NET
https://ignatandrei.github.io/RSCG_Examples/v2/docs/Hardcoded.NET
Category "FilesToCode" has the following generators:
1 Chorn.EmbeddedResourceAccessGenerator
2024-01-21
2 corecraft
2024-02-17
3 Datacute.EmbeddedResourcePropertyGenerator
2024-11-03
4 DotnetYang
2024-06-29
5 EmbedResourceCSharp
2023-04-16
6 Hardcoded.NET
2026-12-23
7 kli.Localize
2025-10-01
8 LingoGen
2024-02-23
9 Maestria.TypeProviders
2026-04-09
10 MagicConstants
2026-09-04
11 NFH.FileEmbed
2025-08-08
12 NotNotAppSettings
2024-01-26
13 Pinecone.TypedPath
2026-08-24
14 Podimo.ConstEmbed
2023-04-16
15 ResXGenerator
2023-10-02
16 RSCG_JSON2Class
2024-02-29
17 RSCG_Sql
2026-11-09
18 RSCG_Utils
2023-04-16
19 Slang.Net
2026-09-11
20 Strings.ResourceGenerator
2025-07-06
21 SvgIconGenerator
2026-04-04
22 ThisAssembly_Resources
2023-09-16
23 ThisAssembly.Strings
2024-07-21
24 TypedPaths
2026-04-01
25 Weave
2024-01-27