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
26 changes: 24 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# RSCG - 208 Examples of Roslyn Source Code Generators / 14 created by Microsoft /
# RSCG - 209 Examples of Roslyn Source Code Generators / 14 created by Microsoft /

## Latest Update : 2025-07-26 => 26 July 2025

Expand All @@ -20,8 +20,30 @@ If you want to be notified each time I add a new RSCG example , please click htt

## Content

Those are the 208 Roslyn Source Code Generators that I have tested you can see and download source code example.
Those are the 209 Roslyn Source Code Generators that I have tested you can see and download source code example.
( including 14 from Microsoft )
### 209. [ShadowWriterProjectInfo](https://ignatandrei.github.io/RSCG_Examples/v2/docs/ShadowWriterProjectInfo) , in the [Builder](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#builder) category

Generated on : 2025-07-24 => 24 July 2025

<details>
<summary>Expand</summary>



Author: Stefan Stolz

Leverage the capabilities of Roslyn source generators to help generate boilerplate code efficiently.

Nuget: [https://www.nuget.org/packages/ShadowWriter/](https://www.nuget.org/packages/ShadowWriter/)


Link: [https://ignatandrei.github.io/RSCG_Examples/v2/docs/ShadowWriterProjectInfo](https://ignatandrei.github.io/RSCG_Examples/v2/docs/ShadowWriterProjectInfo)

Source: [https://github.com/StefanStolz/ShadowWriter](https://github.com/StefanStolz/ShadowWriter)

</details>

### 208. [AsyncIt](https://ignatandrei.github.io/RSCG_Examples/v2/docs/AsyncIt) , in the [Async](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#async) category

Generated on : 2025-07-26 => 26 July 2025
Expand Down
1 change: 1 addition & 0 deletions v2/Generator/all.csv
Original file line number Diff line number Diff line change
Expand Up @@ -207,3 +207,4 @@ Nr,Key,Source,Category
206,ShadowWriterBuilder, https://github.com/StefanStolz/ShadowWriter,Builder
207,AutoInterface, https://github.com/BlackWhiteYoshi/AutoInterface,Interface
208,AsyncIt, https://github.com/oleg-shilo/AsyncIt,Async
209,ShadowWriterProjectInfo, https://github.com/StefanStolz/ShadowWriter,Builder
6 changes: 6 additions & 0 deletions v2/RSCGExamplesData/GeneratorDataRec.json
Original file line number Diff line number Diff line change
Expand Up @@ -1256,5 +1256,11 @@
"Category":35,
"dtStart": "2025-07-26T00:00:00",
"show": true
},
{
"ID":"ShadowWriterProjectInfo",
"Category": 4,
"dtStart": "2025-07-24T00:00:00",
"show": true
}
]
63 changes: 63 additions & 0 deletions v2/book/examples/ShadowWriterProjectInfo.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@

<h1>RSCG nr 209 : ShadowWriterProjectInfo</h1>

<h2>Info</h2>
Nuget : <a href="https://www.nuget.org/packages/ShadowWriter/" target="_blank">https://www.nuget.org/packages/ShadowWriter/</a>

<p>You can find more details at : <a href="https://github.com/StefanStolz/ShadowWriter" target="_blank"> https://github.com/StefanStolz/ShadowWriter</a></p>

<p>Author :Stefan Stolz</p>

<p>Source: <a href="https://github.com/StefanStolz/ShadowWriter" target="_blank">https://github.com/StefanStolz/ShadowWriter</a> </p>

<h2>About</h2>

Generating C# code from project attributes

<h2>
How to use
</h2>
<h3>
Add reference to the <a href="https://www.nuget.org/packages/ShadowWriter/" target="_blank">ShadowWriterProjectInfo</a> in the csproj
</h3>
<img src="images/ShadowWriterProjectInfo/DemoAttr.csproj.png" width="580" height="580" />

<h3>This was for me the <b>starting</b> code</h3>

<br />
I have <b>coded</b> the file Program.cs
<br />
<img src="images/ShadowWriterProjectInfo/csFiles/Program.cs.png" width="580" height="580" />
<hr />
<h3>And here are the <i>generated</i> files</h3>

<br />
The file <i>generated</i> is BuilderAttribute.g.cs
<br />
<img src="images/ShadowWriterProjectInfo/generated/BuilderAttribute.g.cs.png" width="580" height="580" />

<br />
The file <i>generated</i> is NullObjectAttribute.g.cs
<br />
<img src="images/ShadowWriterProjectInfo/generated/NullObjectAttribute.g.cs.png" width="580" height="580" />

<br />
The file <i>generated</i> is ShadowWriter.TheProject.g.cs
<br />
<img src="images/ShadowWriterProjectInfo/generated/ShadowWriter.TheProject.g.cs.png" width="580" height="580" />

<p>
You can download the code and this page as pdf from
<a target="_blank" href='https://ignatandrei.github.io/RSCG_Examples/v2/docs/ShadowWriterProjectInfo'>
https://ignatandrei.github.io/RSCG_Examples/v2/docs/ShadowWriterProjectInfo
</a>
</p>


<p>
You can see the whole list at
<a target="_blank" href='https://ignatandrei.github.io/RSCG_Examples/v2/docs/List-of-RSCG'>
https://ignatandrei.github.io/RSCG_Examples/v2/docs/List-of-RSCG
</a>
</p>

6 changes: 5 additions & 1 deletion v2/book/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
</head>
<body>
<h1>
This is the list of 208 RSCG with examples =>
This is the list of 209 RSCG with examples =>
</h1>

<table >
Expand Down Expand Up @@ -858,6 +858,10 @@ <h1>
<td>208</td>
<td><a href="examples/AsyncIt.html">AsyncIt</a></td>
</tr>
<tr>
<td>209</td>
<td><a href="examples/ShadowWriterProjectInfo.html">ShadowWriterProjectInfo</a></td>
</tr>
</table>


Expand Down
1 change: 1 addition & 0 deletions v2/book/pandocHTML.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ input-files:
- examples/ShadowWriterBuilder.html
- examples/AutoInterface.html
- examples/AsyncIt.html
- examples/ShadowWriterProjectInfo.html

# or you may use input-file: with a single value
# defaults:
Expand Down
22 changes: 22 additions & 0 deletions v2/rscg_examples/ShadowWriterProjectInfo/description.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"generator":{
"name":"ShadowWriterProjectInfo",
"nuget":[
"https://www.nuget.org/packages/ShadowWriter/"
],
"link":"https://github.com/StefanStolz/ShadowWriter",
"author":"Stefan Stolz",
"source":"https://github.com/StefanStolz/ShadowWriter"
},
"data":{
"goodFor":["Generating C# code from project attributes"],
"csprojDemo":"DemoAttr.csproj",
"csFiles":["Program.cs"],
"excludeDirectoryGenerated":[""],
"includeAdditionalFiles":[""]
},
"links":{
"blog":"",
"video":""
}
}
1 change: 1 addition & 0 deletions v2/rscg_examples/ShadowWriterProjectInfo/nuget.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Leverage the capabilities of Roslyn source generators to help generate boilerplate code efficiently.
106 changes: 106 additions & 0 deletions v2/rscg_examples/ShadowWriterProjectInfo/readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# ShadowWriter

[![NuGet](https://img.shields.io/nuget/v/ShadowWriter.svg)](https://www.nuget.org/packages/ShadowWriter)
[![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
[![Build](https://img.shields.io/github/actions/workflow/status/StefanStolz/ShadowWriter/build.yml?branch=main)](https://github.com/StefanStolz/ShadowWriter/actions)

**ShadowWriter** is a Roslyn Source Generator designed to simplify and automate aspects of .NET development.
It currently supports the following features:

## ✨ Features

Samples can be found in the [Source-Code](https://github.com/StefanStolz/ShadowWriter/tree/main/src/ShadowWriter.Sample) or in the [Wiki](https://github.com/StefanStolz/ShadowWriter/wiki).

### 1. Generate Null Objects
The NullObject feature in ShadowWriter provides a simple way to automatically generate null object implementations for interfaces and classes. This pattern is useful for providing default "do nothing" implementations that can help avoid null reference exceptions and simplify code.

#### Usage
To create a null object implementation, simply add the `[NullObject]` attribute to your class:

```csharp
[NullObject]
public partial class ImplementingMyInterface : IMyInterface
{
}
```

### 2. Inject Project Information
Embeds values from the project file (`*.csproj`) directly into your source code.
This is useful for build metadata, version numbers, or project-specific configuration.

#### Available Properties
The generated `TheProject` class provides the following static properties:

| Property | Description | Example |
|----------|-------------|---------|
| `FullPath` | The complete path to the project file | `/path/to/YourProject.csproj` |
| `ProjectDirectory` | The directory containing the project file | `/path/to/` |
| `Name` | The name of the project | `YourProject` |
| `OutDir` | The output directory for compiled artifacts | `/path/to/artifacts/bin/YourProject/debug/` |
| `Version` | The current version of the project | `1.0.0` |
| `RootNamespace` | The root namespace of the project | `YourProject` |

#### Example Usage

```csharp
// Access project information anywhere in your code
Console.WriteLine($"Project Name: {TheProject.Name}");
Console.WriteLine($"Project Version: {TheProject.Version}");
Console.WriteLine($"Project Output Directory: {TheProject.OutDir}");
```


### 3. Experimental: Typed Access to EmbeddedResources
Generates strongly typed wrappers for `EmbeddedResources`, allowing safe and convenient access to resources at runtime.

> ⚠️ Feature #3 is experimental and may change significantly in future versions.

Details can be found in the [Wiki](https://github.com/StefanStolz/ShadowWriter/wiki/ProjectFiles).

### 4. Generate Builders for Records

The **Builder** feature in ShadowWriter automatically generates builder classes for your `record` types. This significantly reduces boilerplate when constructing complex objects, especially with optional and nullable parameters or when you want to use a fluent API pattern for object creation.

#### Usage

To enable builder generation, simply annotate your partial `record` with the `[Builder]` attribute:

```csharp
[Builder]
public partial record WithBuilder(int Number);
```

The generator will create a corresponding builder class (e.g., `WithBuilder.Builder`) with mutable Properties for each Parameter.

#### Examples

A variety of record types are supported:

```csharp
// Record with a single value type
[Builder]
public partial record WithBuilder(int Number);
```

The generated builder enables you to create instances using a clear, chainable API. For example:

```csharp
var builder = new WithBuilder.Builder();
builder.Number = 1;
var item = builder.Build();
```

## 📦 Installation

You can install ShadowWriter via NuGet:

```sh
dotnet package add ShadowWriter
```

⚙️ Usage
ShadowWriter runs automatically during compilation.
No manual setup is needed. Documentation and configuration options will be expanded in future versions.

📄 License
This project is licensed under the MIT License.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@

{
"$schema": "https://aka.ms/codetour-schema",
"title": "ShadowWriterProjectInfo",
"steps":
[
{
"file": "DemoAttr/DemoAttr.csproj",
"description": "First, we add Nuget [ShadowWriter](https://www.nuget.org/packages/ShadowWriter/) in csproj ",
"pattern": "ShadowWriter"
}

,{
"file": "DemoAttr/Program.cs",
"description": "File Program.cs \r\n>> dotnet run --project DemoAttr/DemoAttr.csproj ",
"pattern": "this is the code"
}


,{
"file": "DemoAttr/obj/GX/ShadowWriter/ShadowWriter.ProjectInfoGenerator/ShadowWriter.TheProject.g.cs",
"description": "Generated File 3 from 3 : ShadowWriter.TheProject.g.cs ",
"line": 1
}

,{
"file": "DemoAttr/obj/GX/ShadowWriter/ShadowWriter.NullObjectGenerator/NullObjectAttribute.g.cs",
"description": "Generated File 2 from 3 : NullObjectAttribute.g.cs ",
"line": 1
}

,{
"file": "DemoAttr/obj/GX/ShadowWriter/ShadowWriter.BuilderGenerator/BuilderAttribute.g.cs",
"description": "Generated File 1 from 3 : BuilderAttribute.g.cs ",
"line": 1
}

],

"ref": "main"

}
25 changes: 25 additions & 0 deletions v2/rscg_examples/ShadowWriterProjectInfo/src/DemoAttr.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.14.36408.4 d17.14
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DemoAttr", "DemoAttr\DemoAttr.csproj", "{E7AE387F-3B33-41EF-A809-94E5C21EDBFC}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{E7AE387F-3B33-41EF-A809-94E5C21EDBFC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E7AE387F-3B33-41EF-A809-94E5C21EDBFC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E7AE387F-3B33-41EF-A809-94E5C21EDBFC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E7AE387F-3B33-41EF-A809-94E5C21EDBFC}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {75065D34-E2FE-414E-BE26-D871D5945284}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="ShadowWriter" Version="0.9.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<PropertyGroup>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GX</CompilerGeneratedFilesOutputPath>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Access project information anywhere in your code
using ShadowWriter;
Console.WriteLine($"Project Name: {TheProject.Name}");
Console.WriteLine($"Project Version: {TheProject.Version}");
Console.WriteLine($"Project Build Date: {TheProject.BuildTimeUtc}");
Loading