This repository has been archived and migrated to AltV.Community monorepo.
This library helps you generate the needed code for implementing any MValue adapter.
- Add the NuGet package to your project.
dotnet add package AltV.Community.MValueAdapters.Generators
- (Optional) Enable
EmitCompilerGeneratedFiles
flag in your.csproj
by adding this to your<PropertyGroup>
.
This helps preventing generated files not found issue if you happen to use copy build output task.
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
- (Optional) In case there are CS0436 warnings during compilation, you must add these attributes to your
<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.
- Add
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;
}
- Register the MValue adapters generated when the resource (client / server) starts.
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.
- Fork the project, clone and build it
dotnet build
. - Remove any existing
<PackageReference>
to this project from yourServer
/Client
project. - Add the following lines to an
<ItemGroup>
and replace theInclude=
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" />
- Add the following line to an
<ItemGroup>
in yourServer
/Client
project to view generated files:
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
- In your
Server
/Client
project, make sure you clear the generator cache before building to keep generated files always latest, or you can use the command below which already does that.
dotnet build-server shutdown && dotnet clean && dotnet build
- AltV.Community.Events: create events as classes with both sync and async support.