Rework metadata struct loading to use new struct versioning
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using VersionedSerialization.Generator.Utils;
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using VersionedSerialization.Generator.Utils;
|
||||
|
||||
namespace VersionedSerialization.Generator.Models;
|
||||
|
||||
@@ -6,8 +7,7 @@ public sealed record ObjectSerializationInfo(
|
||||
string Namespace,
|
||||
string Name,
|
||||
bool HasBaseType,
|
||||
bool IsStruct,
|
||||
bool ShouldGenerateSizeMethod,
|
||||
SyntaxKind DefinitionType,
|
||||
bool CanGenerateSizeMethod,
|
||||
ImmutableEquatableArray<PropertySerializationInfo> Properties
|
||||
);
|
||||
@@ -6,6 +6,6 @@ public sealed record PropertySerializationInfo(
|
||||
string Name,
|
||||
string ReadMethod,
|
||||
string SizeExpression,
|
||||
int Alignment,
|
||||
PropertyType Type,
|
||||
ImmutableEquatableArray<VersionCondition> VersionConditions
|
||||
);
|
||||
@@ -16,6 +16,9 @@ public enum PropertyType
|
||||
Int32,
|
||||
Int64,
|
||||
String,
|
||||
Custom,
|
||||
NativeInteger,
|
||||
UNativeInteger,
|
||||
}
|
||||
|
||||
public static class PropertyTypeExtensions
|
||||
@@ -35,6 +38,9 @@ public static class PropertyTypeExtensions
|
||||
PropertyType.Int32 => nameof(PropertyType.Int32),
|
||||
PropertyType.Int64 => nameof(PropertyType.Int64),
|
||||
PropertyType.String => nameof(String),
|
||||
PropertyType.Custom => "",
|
||||
PropertyType.NativeInteger => "NInt",
|
||||
PropertyType.UNativeInteger => "NUInt",
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(type), type, null)
|
||||
};
|
||||
|
||||
@@ -43,6 +49,40 @@ public static class PropertyTypeExtensions
|
||||
{
|
||||
PropertyType.Boolean => true,
|
||||
PropertyType.String => true,
|
||||
PropertyType.Custom => true,
|
||||
PropertyType.NativeInteger => true,
|
||||
PropertyType.UNativeInteger => true,
|
||||
_ => false
|
||||
};
|
||||
|
||||
public static int GetTypeSize(this PropertyType type)
|
||||
=> type switch
|
||||
{
|
||||
PropertyType.Unsupported => -1,
|
||||
PropertyType.None => 0,
|
||||
PropertyType.UInt8 => 1,
|
||||
PropertyType.Int8 => 1,
|
||||
PropertyType.Boolean => 1,
|
||||
PropertyType.UInt16 => 2,
|
||||
PropertyType.UInt32 => 4,
|
||||
PropertyType.UInt64 => 8,
|
||||
PropertyType.Int16 => 2,
|
||||
PropertyType.Int32 => 4,
|
||||
PropertyType.Int64 => 8,
|
||||
PropertyType.String => -1,
|
||||
PropertyType.Custom => -1,
|
||||
PropertyType.NativeInteger => -1,
|
||||
PropertyType.UNativeInteger => -1,
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(type), type, null)
|
||||
};
|
||||
|
||||
public static bool IsUnsignedType(this PropertyType type)
|
||||
=> type switch
|
||||
{
|
||||
PropertyType.UInt8
|
||||
or PropertyType.UInt16
|
||||
or PropertyType.UInt32
|
||||
or PropertyType.UInt64 => true,
|
||||
_ => false
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user