RawAccess.SourceGeneration
2.0.0
dotnet add package RawAccess.SourceGeneration --version 2.0.0
NuGet\Install-Package RawAccess.SourceGeneration -Version 2.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="RawAccess.SourceGeneration" Version="2.0.0"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="RawAccess.SourceGeneration" Version="2.0.0" />
<PackageReference Include="RawAccess.SourceGeneration"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add RawAccess.SourceGeneration --version 2.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: RawAccess.SourceGeneration, 2.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package RawAccess.SourceGeneration@2.0.0
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=RawAccess.SourceGeneration&version=2.0.0
#tool nuget:?package=RawAccess.SourceGeneration&version=2.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
RawAccess
RawAccess is a C# source generator that automatically produces static helper classes for accessing and updating public fields and properties of your types.
It generates:
Get
methods for reading public fields and propertiesWith
methods for creating copies with modified values- Factory methods for constructing instances without manual boilerplate
Example
Given a type:
[GenerateRawAccess]
public class MyClass<TA, TB, TC>
where TA : TB
where TB : IEnumerable<TC>
where TC : class
{
public TA A { get; }
public TB B { get; set; }
public TC C { set { } }
public MyClass(string myString, TA a, TB b, TC c)
{
A = a;
B = b;
C = c;
}
}
RawAccess will generate a static helper class:
public static class MyClassRawAccess
{
public static MyClass<TA, TB, TC> GetMyClass<TA, TB, TC>(string myString, TA a, TB b, TC c) { ... }
public static TA GetA<TA, TB, TC>(MyClass<TA, TB, TC> instance) where ... => instance.A;
public static TB GetB<TA, TB, TC>(MyClass<TA, TB, TC> instance) where ... => instance.B;
public static MyClass<TA, TB, TC> WithB<TA, TB, TC>(MyClass<TA, TB, TC> instance, TB value) where ... { ... }
public static MyClass<TA, TB, TC> WithC<TA, TB, TC>(MyClass<TA, TB, TC> instance, TC value) where ... { ... }
}
Usage
- Add the
[GenerateRawAccess]
attribute to your class, struct, or record. - Build your project.
- Use the generated
*RawAccess
static class to construct, get, and modify instances.
Example test:
var myStruct = MyStructRawAccess.GetMyStruct("str");
var updated = MyStructRawAccess.WithStr(myStruct, "newStr");
Assert.AreEqual("newStr", MyStructRawAccess.GetStr(updated));
License
This project is dedicated to the public domain under the Unlicense.
See the LICENSE file for details.
There are no supported framework assets in this package.
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last Updated |
---|---|---|
2.0.0 | 160 | 9/20/2025 |