add VersionedSerialization + source generator

This commit is contained in:
LukeFZ
2024-08-13 04:27:23 +02:00
parent 30c019c4ef
commit 22ecdc3612
25 changed files with 1585 additions and 0 deletions

View File

@@ -0,0 +1,13 @@
using VersionedSerialization.Generator.Utils;
namespace VersionedSerialization.Generator.Models;
public sealed record ObjectSerializationInfo(
string Namespace,
string Name,
bool HasBaseType,
bool IsStruct,
bool ShouldGenerateSizeMethod,
bool CanGenerateSizeMethod,
ImmutableEquatableArray<PropertySerializationInfo> Properties
);

View File

@@ -0,0 +1,11 @@
using VersionedSerialization.Generator.Utils;
namespace VersionedSerialization.Generator.Models;
public sealed record PropertySerializationInfo(
string Name,
string ReadMethod,
string SizeExpression,
int Alignment,
ImmutableEquatableArray<VersionCondition> VersionConditions
);

View File

@@ -0,0 +1,48 @@
using System;
namespace VersionedSerialization.Generator.Models;
public enum PropertyType
{
Unsupported = -1,
None,
Boolean,
UInt8,
UInt16,
UInt32,
UInt64,
Int8,
Int16,
Int32,
Int64,
String,
}
public static class PropertyTypeExtensions
{
public static string GetTypeName(this PropertyType type)
=> type switch
{
PropertyType.Unsupported => nameof(PropertyType.Unsupported),
PropertyType.None => nameof(PropertyType.None),
PropertyType.UInt8 => nameof(Byte),
PropertyType.Int8 => nameof(SByte),
PropertyType.Boolean => nameof(PropertyType.Boolean),
PropertyType.UInt16 => nameof(PropertyType.UInt16),
PropertyType.UInt32 => nameof(PropertyType.UInt32),
PropertyType.UInt64 => nameof(PropertyType.UInt64),
PropertyType.Int16 => nameof(PropertyType.Int16),
PropertyType.Int32 => nameof(PropertyType.Int32),
PropertyType.Int64 => nameof(PropertyType.Int64),
PropertyType.String => nameof(String),
_ => throw new ArgumentOutOfRangeException(nameof(type), type, null)
};
public static bool IsSeperateMethod(this PropertyType type)
=> type switch
{
PropertyType.Boolean => true,
PropertyType.String => true,
_ => false
};
}

View File

@@ -0,0 +1,3 @@
namespace VersionedSerialization.Generator.Models;
public sealed record VersionCondition(StructVersion? LessThan, StructVersion? GreaterThan, StructVersion? EqualTo, string? IncludingTag, string? ExcludingTag);