A roslyn source generator for MValue adapter implementation in alt:V
License
—
Deps
0
Install Size
—
Vulns
✓ 0
Published
Oct 19, 2024
$ dotnet add package AltV.Community.MValueAdapters.Generatorsdotnet add package AltV.Community.MValueAdapters.Generators
<PackageReference>.<PackageReference Include="AltV.Community.MValueAdapters.Generators" PrivateAssets="all" ExcludeAssets="runtime" />
Note: If you use a shared project between client and server, only add the NuGet to the shared project and neither to the client nor server project to avoid ambigious references.
MValueAdapter attribute to your class.using AltV.Community.MValueAdapters.Generators;
[MValueAdapter]
public class ParentDto
{
public string First { get; set; } = string.Empty;
public string Second { get; set; } = string.Empty;
public ChildDto Dto { get; set; } = null!;
}
[MValueAdapter]
public class ChildDto
{
public string First { get; set; } = string.Empty;
public string Second { get; set; } = string.Empty;
}
public override void OnStart()
{
AltExtensions.RegisterAdapters();
}
Huge thanks to deluvas1911 for sharing his great work and allowing me to open source this.
If you'd like to contribute, some adjustments need to be made to the project setup.
dotnet build.<PackageReference> to this project from your Server/Client project.<ItemGroup> and replace the Include= value with the relative paths:<ProjectReference Include="..\AltV.Community.MValueAdapters.Generators\AltV.Community.MValueAdapters.Generators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" PrivateAssets="all" />
<ProjectReference Include="..\AltV.Community.MValueAdapters.Generators.Abstractions\AltV.Community.MValueAdapters.Generators.Abstractions.csproj" OutputItemType="Analyzer" />
<ItemGroup> in your Server/Client project to view generated files:<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
Server/Client project, run dotnet clean before building, to ensure cache is cleared.