-
-
Notifications
You must be signed in to change notification settings - Fork 6
docs #535
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
docs #535
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| # Just later | ||
|
|
||
| ## Latest Update : 2026-08-24 => 24 August 2026 | ||
| ## Latest Update : 2026-08-26 => 26 August 2026 | ||
|
|
||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
|
|
||
| { | ||
| "$schema": "https://aka.ms/codetour-schema", | ||
| "title": "PropertyResolvers", | ||
| "steps": | ||
| [ | ||
| { | ||
| "file": "rscg_examples/PropertyResolvers/src/PropSwitch/PropSwitch.csproj", | ||
| "description": "First, we add Nuget [PropertyResolvers](https://www.nuget.org/packages/PropertyResolvers/) in csproj ", | ||
| "pattern": "PropertyResolvers" | ||
| } | ||
|
|
||
| ,{ | ||
| "file": "rscg_examples/PropertyResolvers/src/PropSwitch/Program.cs", | ||
| "description": "File Program.cs \r\n>> dotnet run --project rscg_examples/PropertyResolvers/src/PropSwitch/PropSwitch.csproj ", | ||
| "pattern": "this is the code" | ||
| } | ||
|
|
||
| ,{ | ||
| "file": "rscg_examples/PropertyResolvers/src/PropSwitch/Data.cs", | ||
| "description": "File Data.cs ", | ||
| "pattern": "this is the code" | ||
| } | ||
|
|
||
|
|
||
| ,{ | ||
| "file": "rscg_examples/PropertyResolvers/src/PropSwitch/obj/GX/PropertyResolvers.Generators/PropertyResolvers.Generators.PropertyResolverGenerator/PropertyResolverRegistration.g.cs", | ||
| "description": "Generated File 2 from 2 : PropertyResolverRegistration.g.cs ", | ||
| "line": 1 | ||
| } | ||
|
|
||
| ,{ | ||
| "file": "rscg_examples/PropertyResolvers/src/PropSwitch/obj/GX/PropertyResolvers.Generators/PropertyResolvers.Generators.PropertyResolverGenerator/NameResolver.g.cs", | ||
| "description": "Generated File 1 from 2 : NameResolver.g.cs ", | ||
| "line": 1 | ||
| } | ||
|
|
||
| ], | ||
|
|
||
| "ref": "main" | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
|
|
||
| <h1>RSCG nr 285 : PropertyResolvers</h1> | ||
|
|
||
| <h2>Info</h2> | ||
| Nuget : <a href="https://www.nuget.org/packages/PropertyResolvers/" target="_blank">https://www.nuget.org/packages/PropertyResolvers/</a> | ||
|
|
||
| <p>You can find more details at : <a href="https://github.com/tombiddulph/PropertyResolvers" target="_blank"> https://github.com/tombiddulph/PropertyResolvers</a></p> | ||
|
|
||
| <p>Author :Tom Biddulph</p> | ||
|
|
||
| <p>Source: <a href="https://github.com/tombiddulph/PropertyResolvers" target="_blank">https://github.com/tombiddulph/PropertyResolvers</a> </p> | ||
|
|
||
| <h2>About</h2> | ||
|
|
||
| Generating code for switch for property in C# | ||
|
|
||
| <h2> | ||
| How to use | ||
| </h2> | ||
| <h3> | ||
| Add reference to the <a href="https://www.nuget.org/packages/PropertyResolvers/" target="_blank">PropertyResolvers</a> in the csproj | ||
| </h3> | ||
| <img src="images/PropertyResolvers/PropSwitch.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 Data.cs | ||
| <br /> | ||
| <img src="images/PropertyResolvers/csFiles/Data.cs.png" width="580" height="580" /> | ||
| <hr /> | ||
|
|
||
| <br /> | ||
| I have <b>coded</b> the file Program.cs | ||
| <br /> | ||
| <img src="images/PropertyResolvers/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 NameResolver.g.cs | ||
| <br /> | ||
| <img src="images/PropertyResolvers/generated/NameResolver.g.cs.png" width="580" height="580" /> | ||
|
|
||
| <br /> | ||
| The file <i>generated</i> is PropertyResolverRegistration.g.cs | ||
| <br /> | ||
| <img src="images/PropertyResolvers/generated/PropertyResolverRegistration.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/PropertyResolvers'> | ||
| https://ignatandrei.github.io/RSCG_Examples/v2/docs/PropertyResolvers | ||
| </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> | ||
|
|
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -17,7 +17,7 @@ | |||||
| </head> | ||||||
| <body> | ||||||
| <h1> | ||||||
| This is the list of 284 RSCG with examples => | ||||||
| This is the list of 285 RSCG with examples => | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win Escape the HTMLHint 1.9.2 reports Proposed fix-This is the list of 285 RSCG with examples =>
+This is the list of 285 RSCG with examples =>📝 Committable suggestion
Suggested change
🧰 Tools🪛 HTMLHint (1.9.2)[error] 20-20: Special characters must be escaped : [ > ]. (spec-char-escape) 🤖 Prompt for AI AgentsSource: Linters/SAST tools |
||||||
| </h1> | ||||||
|
|
||||||
| <table > | ||||||
|
|
@@ -1162,6 +1162,10 @@ <h1> | |||||
| <td>284</td> | ||||||
| <td><a href="examples/Pinecone.TypedPath.html">Pinecone.TypedPath</a></td> | ||||||
| </tr> | ||||||
| <tr> | ||||||
| <td>285</td> | ||||||
| <td><a href="examples/PropertyResolvers.html">PropertyResolvers</a></td> | ||||||
| </tr> | ||||||
| </table> | ||||||
|
|
||||||
|
|
||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| { | ||
| "generator":{ | ||
| "name":"PropertyResolvers", | ||
| "nuget":[ | ||
| "https://www.nuget.org/packages/PropertyResolvers/" | ||
| ], | ||
| "link":"https://github.com/tombiddulph/PropertyResolvers", | ||
| "author":"Tom Biddulph", | ||
| "source":"https://github.com/tombiddulph/PropertyResolvers" | ||
| }, | ||
| "data":{ | ||
| "goodFor":["Generating code for switch for property in C#"], | ||
| "csprojDemo":"PropSwitch.csproj", | ||
| "csFiles":["Data.cs","Program.cs"], | ||
| "excludeDirectoryGenerated":[""], | ||
| "includeAdditionalFiles":[""] | ||
| }, | ||
| "links":{ | ||
| "blog":"", | ||
| "video":"" | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| A source generator that creates property resolver classes for types with | ||
| matching properties. Use assembly-level attributes to generate resolvers that can | ||
| retrieve property values from objects at runtime. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,130 @@ | ||
| # PropertyResolvers | ||
|
|
||
| A C# source generator that creates type-safe property resolver classes. Instead of using reflection at runtime to extract property values from objects, PropertyResolvers generates compile-time switch expressions that efficiently resolve property values across multiple types. | ||
|
|
||
| ## Installation | ||
|
|
||
| ```bash | ||
| dotnet add package PropertyResolvers | ||
| ``` | ||
|
Comment on lines
+7
to
+9
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win 🔎 Supported by static analysis🏁 Script executed: #!/bin/bash
set -eu
printf '%s\n' '--- documented guides ---'
sed -n '1,20p' v2/rscg_examples/PropertyResolvers/readme.txt
sed -n '52,68p' v2/rscg_examples_site/docs/RSCG-Examples/PropertyResolvers.md
printf '%s\n' '--- project files and package references ---'
fd -i -t f '.*\.(csproj|props|targets)$' v2/rscg_examples/PropertyResolvers v2/rscg_examples_site | sort
rg -n -C 3 'PropertyResolvers(\.Attributes)?|PackageReference' v2/rscg_examples/PropertyResolvers v2/rscg_examples_siteRepository: ignatandrei/RSCG_Examples Length of output: 50384 🏁 Script executed: #!/bin/bash
set -eu
printf '%s\n' '--- guide excerpts ---'
sed -n '1,14p' v2/rscg_examples/PropertyResolvers/readme.txt
sed -n '56,66p' v2/rscg_examples_site/docs/RSCG-Examples/PropertyResolvers.md
printf '%s\n' '--- PropertyResolvers project references ---'
rg -n -C 4 'PropertyResolvers(\.Attributes)?|PackageReference' v2/rscg_examples/PropertyResolvers
printf '%s\n' '--- NuGet manifests for version 0.0.9 ---'
for id in propertyresolvers propertyresolvers.attributes; do
url="https://api.nuget.org/v3-flatcontainer/${id}/0.0.9/${id}.nuspec"
printf '%s\n' "--- ${url} ---"
curl --fail --silent --show-error "$url" | sed -n '1,240p'
doneRepository: ignatandrei/RSCG_Examples Length of output: 12020 Add
📍 Affects 2 files
🤖 Prompt for AI Agents |
||
|
|
||
| ## Quick Start | ||
|
|
||
| 1. Add assembly-level attributes to specify which properties you want resolvers for: | ||
|
|
||
| ```csharp | ||
| using PropertyResolvers.Attributes; | ||
|
|
||
| [assembly: GeneratePropertyResolver("AccountId")] | ||
| [assembly: GeneratePropertyResolver("TenantId")] | ||
| ``` | ||
|
|
||
| 2. The generator automatically finds all types with matching properties and generates resolver classes: | ||
|
|
||
| ```csharp | ||
| // Generated code (AccountIdResolver.g.cs) | ||
| public static class AccountIdResolver | ||
| { | ||
| public static string? GetAccountId(object? obj) => obj switch | ||
| { | ||
| global::MyApp.Order x => x.AccountId.ToString(), | ||
| global::MyApp.Customer x => x.AccountId.ToString(), | ||
| global::MyApp.Invoice x => x.AccountId.ToString(), | ||
| _ => null | ||
| }; | ||
| } | ||
| ``` | ||
|
|
||
| 3. Use the generated resolvers in your code: | ||
|
|
||
| ```csharp | ||
| var order = new Order { AccountId = "ACC-123" }; | ||
| var customer = new Customer { AccountId = "ACC-456" }; | ||
| var product = new Product { Name = "Widget" }; // No AccountId property | ||
|
|
||
| var id1 = AccountIdResolver.GetAccountId(order); // "ACC-123" | ||
| var id2 = AccountIdResolver.GetAccountId(customer); // "ACC-456" | ||
| var id3 = AccountIdResolver.GetAccountId(product); // null | ||
| ``` | ||
|
|
||
| ## Use Cases | ||
|
|
||
| - **Multi-tenant applications**: Extract `TenantId` from any entity without reflection | ||
| - **Audit logging**: Consistently retrieve identifier properties across different entity types | ||
| - **Event sourcing**: Extract aggregate IDs from various event types | ||
| - **API responses**: Normalize property access across different DTO types | ||
|
|
||
| ## Configuration Options | ||
|
|
||
| ### Basic Usage | ||
|
|
||
| ```csharp | ||
| [assembly: GeneratePropertyResolver("AccountId")] | ||
| ``` | ||
|
|
||
| ### Namespace Filtering | ||
|
|
||
| Include only specific namespaces: | ||
|
|
||
| ```csharp | ||
| [assembly: GeneratePropertyResolver("AccountId", IncludeNamespaces = new[] { "MyApp.Domain", "MyApp.Entities" })] | ||
| ``` | ||
|
|
||
| Exclude specific namespaces: | ||
|
|
||
| ```csharp | ||
| [assembly: GeneratePropertyResolver("AccountId", ExcludeNamespaces = new[] { "System", "Microsoft" })] | ||
| ``` | ||
|
|
||
| ### Multiple Resolvers | ||
|
|
||
| You can generate resolvers for multiple properties: | ||
|
|
||
| ```csharp | ||
| [assembly: GeneratePropertyResolver("AccountId", ExcludeNamespaces = new[] { "System", "Microsoft" })] | ||
| [assembly: GeneratePropertyResolver("TenantId", ExcludeNamespaces = new[] { "System", "Microsoft" })] | ||
| [assembly: GeneratePropertyResolver("EntityId", ExcludeNamespaces = new[] { "System", "Microsoft" })] | ||
| ``` | ||
|
|
||
| ## Attribute Reference | ||
|
|
||
| ### `GeneratePropertyResolverAttribute` | ||
|
|
||
| | Parameter | Type | Description | | ||
| |-----------|------|-------------| | ||
| | `propertyName` | `string` | **(Required)** The name of the property to generate a resolver for. Case-insensitive matching. | | ||
| | `IncludeNamespaces` | `string[]?` | Only include types from these namespaces (prefix match). | | ||
| | `ExcludeNamespaces` | `string[]?` | Exclude types from these namespaces (prefix match). | | ||
|
|
||
| ## Analyzer | ||
|
|
||
| The package includes an analyzer that detects duplicate property resolver definitions: | ||
|
|
||
| ```csharp | ||
| // PR001: Property resolver for 'AccountId' is already defined | ||
| [assembly: GeneratePropertyResolver("AccountId")] | ||
| [assembly: GeneratePropertyResolver("AccountId")] // Error: duplicate | ||
| ``` | ||
|
|
||
| Duplicate detection is case-insensitive, so `"AccountId"` and `"accountid"` are considered duplicates. | ||
|
|
||
| ## How It Works | ||
|
|
||
| 1. The generator scans all assembly-level `GeneratePropertyResolver` attributes | ||
| 2. For each attribute, it finds all classes and structs with a matching property name | ||
| 3. It generates a static resolver class with a switch expression that pattern-matches on the object type | ||
| 4. The generated code uses `global::` prefixes to avoid namespace conflicts | ||
|
|
||
| ## Generated Code Location | ||
|
|
||
| The generated resolver classes are placed in a namespace matching your assembly name. For example, if your assembly is `MyApp`, the resolvers will be in the `MyApp` namespace. | ||
|
|
||
| ## Requirements | ||
|
|
||
| - .NET Standard 2.0 compatible (works with .NET Framework 4.7.2+ and .NET Core 2.0+) | ||
| - C# 9.0 or later (for switch expressions in generated code) | ||
| - Visual Studio 2022 17.0+ or compatible IDE with Roslyn 4.0+ support | ||
|
|
||
| ## License | ||
|
|
||
| MIT | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| <Solution> | ||
| <Project Path="PropSwitch/PropSwitch.csproj" /> | ||
| </Solution> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: ignatandrei/RSCG_Examples
Length of output: 347
🏁 Script executed:
Repository: ignatandrei/RSCG_Examples
Length of output: 6173
Build
PropSwitchbefore opening the generated-file steps.The tour only displays
dotnet runin theProgram.csdescription. It does not execute the build before opening files generated underobj/GX. Add an explicit build step or use checked-in documentation assets.🤖 Prompt for AI Agents