riffy / AltV.Community.MValueAdapters.Generators

A roslyn source generator for MValue adapter implementation in alt:V

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

AltV.Community.MValueAdapters.Generators

NuGet badge

Quickstart

Installation

  1. Add the NuGet package to your project.
dotnet add package AltV.Community.MValueAdapters.Generators
  1. 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.

Generate your first MValue adapter

  1. 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;
}
  1. 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.

About

A roslyn source generator for MValue adapter implementation in alt:V


Languages

Language:C# 100.0%