add VersionedSerialization + source generator
This commit is contained in:
@@ -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
|
||||
);
|
||||
@@ -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
|
||||
);
|
||||
48
VersionedSerialization.Generator/Models/PropertyType.cs
Normal file
48
VersionedSerialization.Generator/Models/PropertyType.cs
Normal 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
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
namespace VersionedSerialization.Generator.Models;
|
||||
|
||||
public sealed record VersionCondition(StructVersion? LessThan, StructVersion? GreaterThan, StructVersion? EqualTo, string? IncludingTag, string? ExcludingTag);
|
||||
Reference in New Issue
Block a user