diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..f410d53 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,31 @@ +name: Build and Test + +on: + push: + branches: [ main ] + pull_request: + +env: + BUILD_CONFIG: Release + +jobs: + build-and-test: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Setup .NET SDK + uses: actions/setup-dotnet@v4 + with: + dotnet-version: '10.0.x' + + - name: Restore dependencies + run: dotnet restore + + - name: Build + run: dotnet build -c Release --no-restore + + - name: Test + run: dotnet test -c Release --no-build --verbosity normal diff --git a/.gitignore b/.gitignore index 3ce9469..6ea7526 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,5 @@ .DS_Store /packages/* + +BenchmarkDotNet.Artifacts/ diff --git a/ModernUO.Serialization.Generator.Benchmarks/GeneratorBenchmarks.cs b/ModernUO.Serialization.Generator.Benchmarks/GeneratorBenchmarks.cs new file mode 100644 index 0000000..4cb5ec8 --- /dev/null +++ b/ModernUO.Serialization.Generator.Benchmarks/GeneratorBenchmarks.cs @@ -0,0 +1,163 @@ +/************************************************************************* + * ModernUO * + * Copyright 2019-2026 - ModernUO Development Team * + * Email: hi@modernuo.com * + * File: GeneratorBenchmarks.cs * + * * + * This program is free software: you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation, either version 3 of the License, or * + * (at your option) any later version. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see . * + *************************************************************************/ + +using System.Collections.Immutable; +using System.Text; +using BenchmarkDotNet.Attributes; +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp; +using ModernUO.Serialization.Generator; +using ModernUO.Serialization.Generator.Tests.Helpers; + +namespace ModernUO.Serialization.Generator.Benchmarks; + +/// +/// Measures the generator over a synthetic corpus: a cold full run, and the incremental +/// re-run cost after editing a single file - the operation an IDE performs constantly. +/// A correctly incremental pipeline keeps the re-run near the cost of one class; a broken +/// one re-runs the whole corpus. +/// +[MemoryDiagnoser] +public class GeneratorBenchmarks +{ + [Params(150)] + public int ClassCount { get; set; } + + private CSharpCompilation _compilation = null!; + private ImmutableArray _additionalTexts; + private List _references = null!; + + private GeneratorDriver _warmDriver = null!; + private CSharpCompilation _warmCompilation = null!; + private SyntaxTree _editTarget = null!; + private bool _editToggle; + + [GlobalSetup] + public void Setup() + { + var trustedAssemblies = ((string)AppContext.GetData("TRUSTED_PLATFORM_ASSEMBLIES")!) + .Split(Path.PathSeparator); + + _references = trustedAssemblies + .Where(p => !string.IsNullOrEmpty(p)) + .Select(p => (MetadataReference)MetadataReference.CreateFromFile(p)) + .Concat([MetadataReference.CreateFromFile(typeof(SerializationGeneratorAttribute).Assembly.Location)]) + .ToList(); + + var trees = new List + { + CSharpSyntaxTree.ParseText(SourceGeneratorTestHelper.ServerStubs) + }; + + var additionalTexts = ImmutableArray.CreateBuilder(); + + for (var i = 0; i < ClassCount; i++) + { + trees.Add(CSharpSyntaxTree.ParseText(BuildClassSource(i))); + additionalTexts.Add( + new InMemoryAdditionalText($"Server.TestContent.BenchItem{i}.v0.json", BuildMigrationJson(i)) + ); + } + + _additionalTexts = additionalTexts.ToImmutable(); + _compilation = CSharpCompilation.Create( + "BenchmarkAssembly", + trees, + _references, + new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary) + ); + + // Warm state for the incremental benchmark: one full run, then per-invocation edits. + _warmDriver = CSharpGeneratorDriver + .Create(new EntitySerializationGenerator()) + .AddAdditionalTexts(_additionalTexts) + .RunGenerators(_compilation); + _warmCompilation = _compilation; + _editTarget = _warmCompilation.SyntaxTrees.Last(); + } + + [Benchmark] + public GeneratorDriver ColdFullRun() => + CSharpGeneratorDriver + .Create(new EntitySerializationGenerator()) + .AddAdditionalTexts(_additionalTexts) + .RunGenerators(_compilation); + + [Benchmark] + public GeneratorDriver WarmRerunAfterSingleEdit() + { + // Toggle one file between two whitespace variants so every invocation is a real edit. + _editToggle = !_editToggle; + var text = _editTarget.GetText().ToString(); + var edited = _editToggle ? text + "\n// edit\n" : text.Replace("\n// edit\n", ""); + var newTree = CSharpSyntaxTree.ParseText(edited); + + _warmCompilation = _warmCompilation.ReplaceSyntaxTree(_editTarget, newTree); + _editTarget = newTree; + + _warmDriver = _warmDriver.RunGenerators(_warmCompilation); + return _warmDriver; + } + + private static string BuildClassSource(int index) + { + var sb = new StringBuilder(); + sb.AppendLine("using System;"); + sb.AppendLine("using ModernUO.Serialization;"); + sb.AppendLine("using Server;"); + sb.AppendLine(); + sb.AppendLine("namespace Server.TestContent"); + sb.AppendLine("{"); + sb.AppendLine(" [SerializationGenerator(1)]"); + sb.AppendLine($" public partial class BenchItem{index} : ISerializable"); + sb.AppendLine(" {"); + + for (var f = 0; f < 6; f++) + { + sb.AppendLine($" [SerializableField({f})]"); + sb.AppendLine($" private {(f % 2 == 0 ? "int" : "string")} _field{f};"); + sb.AppendLine(); + } + + sb.AppendLine(" public DateTime Created { get; set; }"); + sb.AppendLine(" public Serial Serial { get; }"); + sb.AppendLine(" public bool Deleted => false;"); + sb.AppendLine(" public void Delete() { }"); + sb.AppendLine(); + sb.AppendLine(" private void MigrateFrom(V0Content content)"); + sb.AppendLine(" {"); + sb.AppendLine(" _field0 = content.Field0;"); + sb.AppendLine(" }"); + sb.AppendLine(" }"); + sb.AppendLine("}"); + + return sb.ToString(); + } + + private static string BuildMigrationJson(int index) => + $$""" + { + "version": 0, + "type": "Server.TestContent.BenchItem{{index}}", + "properties": [ + { + "name": "Field0", + "type": "int", + "rule": "PrimitiveTypeMigrationRule" + } + ] + } + """; +} diff --git a/ModernUO.Serialization.Generator.Benchmarks/ModernUO.Serialization.Generator.Benchmarks.csproj b/ModernUO.Serialization.Generator.Benchmarks/ModernUO.Serialization.Generator.Benchmarks.csproj new file mode 100644 index 0000000..514db43 --- /dev/null +++ b/ModernUO.Serialization.Generator.Benchmarks/ModernUO.Serialization.Generator.Benchmarks.csproj @@ -0,0 +1,26 @@ + + + + Exe + net10.0 + preview + enable + false + + + + + + + + + + + + + + + + + + diff --git a/ModernUO.Serialization.Generator.Benchmarks/Program.cs b/ModernUO.Serialization.Generator.Benchmarks/Program.cs new file mode 100644 index 0000000..8ee24d0 --- /dev/null +++ b/ModernUO.Serialization.Generator.Benchmarks/Program.cs @@ -0,0 +1,3 @@ +using BenchmarkDotNet.Running; + +BenchmarkSwitcher.FromAssembly(typeof(ModernUO.Serialization.Generator.Benchmarks.GeneratorBenchmarks).Assembly).Run(args); diff --git a/ModernUO.Serialization.Generator.DiffTool/Application.cs b/ModernUO.Serialization.Generator.DiffTool/Application.cs new file mode 100644 index 0000000..969cc55 --- /dev/null +++ b/ModernUO.Serialization.Generator.DiffTool/Application.cs @@ -0,0 +1,114 @@ +/************************************************************************* + * ModernUO * + * Copyright 2019-2026 - ModernUO Development Team * + * Email: hi@modernuo.com * + * File: Application.cs * + * * + * This program is free software: you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation, either version 3 of the License, or * + * (at your option) any later version. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see . * + *************************************************************************/ + +using System.Collections.Immutable; +using System.Diagnostics; +using System.Security.Cryptography; +using System.Text; +using System.Text.RegularExpressions; +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp; +using Microsoft.CodeAnalysis.Text; +using ModernUO.Serialization.Generator; +using ModernUO.Serialization.SchemaGenerator; + +namespace ModernUO.Serialization.DiffTool; + +/// +/// Runs the generator against every project in a solution and writes a deterministic manifest +/// of hint names and content hashes. Running it before and after a generator change and +/// diffing the manifests proves the change is output-identical across the real corpus. +/// +public static class Application +{ + public static async Task Main(string[] args) + { + if (args.Length < 2) + { + Console.WriteLine( + "Usage: ModernUO.Serialization.Generator.DiffTool " + ); + return 1; + } + + var solutionPath = args[0]; + var outputFile = args[1]; + + var stopwatch = Stopwatch.StartNew(); + var lines = new List(); + + foreach (var project in await SourceCodeAnalysis.GetProjectsAsync(solutionPath)) + { + var compilation = await project.GetCompilationAsync(); + if (compilation == null) + { + Console.WriteLine($"Skipped {project.Name}: no compilation."); + continue; + } + + var additionalTexts = ImmutableArray.CreateBuilder(); + foreach (var document in project.AdditionalDocuments) + { + if (document.FilePath != null) + { + additionalTexts.Add(new DocumentAdditionalText(document.FilePath, await document.GetTextAsync())); + } + } + + GeneratorDriver driver = CSharpGeneratorDriver + .Create(new EntitySerializationGenerator()) + .AddAdditionalTexts(additionalTexts.ToImmutable()); + + driver = driver.RunGenerators(compilation); + var result = driver.GetRunResult().Results[0]; + + foreach (var source in result.GeneratedSources) + { + var normalized = Normalize(source.SourceText.ToString()); + var hash = Convert.ToHexString(SHA256.HashData(Encoding.UTF8.GetBytes(normalized))); + lines.Add($"{project.Name}\t{source.HintName}\t{hash}"); + } + + foreach (var group in result.Diagnostics.GroupBy(d => d.Id).OrderBy(g => g.Key, StringComparer.Ordinal)) + { + lines.Add($"{project.Name}\t#diagnostics\t{group.Key}x{group.Count()}"); + } + + Console.WriteLine($"Hashed {result.GeneratedSources.Length} sources for {project.Name}."); + } + + lines.Sort(StringComparer.Ordinal); + await File.WriteAllTextAsync(outputFile, string.Join("\n", lines) + "\n"); + + Console.WriteLine($"Wrote {lines.Count} manifest lines to {outputFile} in {stopwatch.Elapsed.TotalSeconds:N2}s."); + return 0; + } + + // Version-stamped headers and line endings are normalized so manifests compare across + // generator versions and checkout styles. + private static string Normalize(string content) => + Regex.Replace( + content.Replace("\r\n", "\n"), + """(Version: |"ModernUO\.Serialization\.Generator", ")\d+\.\d+\.\d+\.\d+""", + "$1{VERSION}" + ); + + private sealed class DocumentAdditionalText(string path, SourceText text) : AdditionalText + { + public override string Path => path; + + public override SourceText GetText(CancellationToken cancellationToken = default) => text; + } +} diff --git a/ModernUO.Serialization.Generator.DiffTool/ModernUO.Serialization.Generator.DiffTool.csproj b/ModernUO.Serialization.Generator.DiffTool/ModernUO.Serialization.Generator.DiffTool.csproj new file mode 100644 index 0000000..e5e61b8 --- /dev/null +++ b/ModernUO.Serialization.Generator.DiffTool/ModernUO.Serialization.Generator.DiffTool.csproj @@ -0,0 +1,20 @@ + + + + Exe + net10.0 + preview + enable + false + + + + + + + + + + + + diff --git a/ModernUO.Serialization.Generator.Tests/Helpers/SourceGeneratorTestHelper.cs b/ModernUO.Serialization.Generator.Tests/Helpers/SourceGeneratorTestHelper.cs index 966b89f..3c34ac1 100644 --- a/ModernUO.Serialization.Generator.Tests/Helpers/SourceGeneratorTestHelper.cs +++ b/ModernUO.Serialization.Generator.Tests/Helpers/SourceGeneratorTestHelper.cs @@ -16,7 +16,7 @@ namespace Server { public interface IGenericReader { - string ReadString(); + string ReadString(bool intern = false); int ReadInt(); uint ReadUInt(); long ReadLong(); @@ -38,8 +38,8 @@ public interface IGenericReader Serial ReadSerial(); Point2D ReadPoint2D(); Point3D ReadPoint3D(); - Rectangle2D ReadRectangle2D(); - Rectangle3D ReadRectangle3D(); + Rectangle2D ReadRect2D(); + Rectangle3D ReadRect3D(); } public interface IGenericWriter @@ -63,6 +63,7 @@ public interface IGenericWriter void Write(System.Guid value); void WriteEncodedInt(int value); void Write(T value) where T : struct, System.Enum; + void WriteEnum(T value) where T : struct, System.Enum; void Write(Serial value); void Write(Point2D value); void Write(Point3D value); @@ -70,43 +71,76 @@ public interface IGenericWriter void Write(Rectangle3D value); } - public interface ISerializable + public interface IGenericSerializable { - Serial Serial { get; } void Serialize(IGenericWriter writer); + } + + public interface ISerializable : IGenericSerializable + { + System.DateTime Created { get; set; } + Serial Serial { get; } void Deserialize(IGenericReader reader); - void MarkDirty(); + bool Deleted { get; } + void Delete(); } public static class ISerializableExtensions { - public static void MarkDirty(ISerializable entity) { } + public static void MarkDirty(this ISerializable entity) { } + } + + public static class Utility + { + public static void Tidy(this System.Collections.Generic.List list) where T : ISerializable { } + public static void Tidy(this System.Collections.Generic.HashSet set) where T : ISerializable { } + public static void Tidy(this System.Collections.Generic.Dictionary dictionary) { } } public readonly struct Serial { public readonly uint Value; public Serial(uint value) => Value = value; + public static bool operator ==(Serial l, Serial r) => l.Value == r.Value; + public static bool operator !=(Serial l, Serial r) => l.Value != r.Value; + public override bool Equals(object obj) => obj is Serial other && Value == other.Value; + public override int GetHashCode() => (int)Value; } public struct Point2D { public int X, Y; + public static bool operator ==(Point2D l, Point2D r) => l.X == r.X && l.Y == r.Y; + public static bool operator !=(Point2D l, Point2D r) => !(l == r); + public override bool Equals(object obj) => obj is Point2D other && this == other; + public override int GetHashCode() => X ^ Y; } public struct Point3D { public int X, Y, Z; + public static bool operator ==(Point3D l, Point3D r) => l.X == r.X && l.Y == r.Y && l.Z == r.Z; + public static bool operator !=(Point3D l, Point3D r) => !(l == r); + public override bool Equals(object obj) => obj is Point3D other && this == other; + public override int GetHashCode() => X ^ Y ^ Z; } public struct Rectangle2D { public Point2D Start, End; + public static bool operator ==(Rectangle2D l, Rectangle2D r) => l.Start == r.Start && l.End == r.End; + public static bool operator !=(Rectangle2D l, Rectangle2D r) => !(l == r); + public override bool Equals(object obj) => obj is Rectangle2D other && this == other; + public override int GetHashCode() => Start.GetHashCode() ^ End.GetHashCode(); } public struct Rectangle3D { public Point3D Start, End; + public static bool operator ==(Rectangle3D l, Rectangle3D r) => l.Start == r.Start && l.End == r.End; + public static bool operator !=(Rectangle3D l, Rectangle3D r) => !(l == r); + public override bool Equals(object obj) => obj is Rectangle3D other && this == other; + public override int GetHashCode() => Start.GetHashCode() ^ End.GetHashCode(); } public class TextDefinition @@ -133,6 +167,12 @@ public class Map public class Timer { public System.TimeSpan Delay { get; set; } + public System.DateTime Next { get; set; } + } + + public static class Core + { + public static System.DateTime Now => System.DateTime.UtcNow; } } """; @@ -198,6 +238,71 @@ public static (ImmutableArray Diagnostics, string? GeneratedSource) return (diagnostics, generatedSource); } + /// + /// Runs the generator and returns every generated source, keyed by file name, along with + /// generator diagnostics and any compile errors in the output compilation. Used by the + /// snapshot tests to pin exact output. + /// + public static ( + ImmutableArray Diagnostics, + ImmutableArray<(string FileName, string Content)> Sources, + ImmutableArray CompileErrors + ) RunGeneratorAllOutputs( + string sourceCode, + IEnumerable<(string fileName, string content)>? additionalTexts = null) + { + var syntaxTrees = new List + { + CSharpSyntaxTree.ParseText(sourceCode), + CSharpSyntaxTree.ParseText(ServerStubs) + }; + + var trustedAssemblies = ((string)AppContext.GetData("TRUSTED_PLATFORM_ASSEMBLIES")!) + .Split(Path.PathSeparator); + + var references = trustedAssemblies + .Where(p => !string.IsNullOrEmpty(p)) + .Select(p => MetadataReference.CreateFromFile(p)) + .Cast() + .Concat([MetadataReference.CreateFromFile(typeof(SerializationGeneratorAttribute).Assembly.Location)]) + .ToList(); + + var compilation = CSharpCompilation.Create( + "TestAssembly", + syntaxTrees, + references, + new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary) + ); + + var generator = new EntitySerializationGenerator(); + + var additionalTextsList = new List(); + if (additionalTexts != null) + { + foreach (var (fileName, content) in additionalTexts) + { + additionalTextsList.Add(new InMemoryAdditionalText(fileName, content)); + } + } + + var driver = CSharpGeneratorDriver.Create(generator) + .AddAdditionalTexts(ImmutableArray.CreateRange(additionalTextsList)); + + driver.RunGeneratorsAndUpdateCompilation(compilation, out var outputCompilation, out var diagnostics); + + var sources = outputCompilation.SyntaxTrees + .Where(st => st.FilePath.EndsWith(".Serialization.g.cs")) + .Select(st => (Path.GetFileName(st.FilePath), st.GetText().ToString())) + .ToImmutableArray(); + + var compileErrors = outputCompilation + .GetDiagnostics() + .Where(d => d.Severity == DiagnosticSeverity.Error) + .ToImmutableArray(); + + return (diagnostics, sources, compileErrors); + } + public static bool HasDiagnostic(ImmutableArray diagnostics, string diagnosticId) { return diagnostics.Any(d => d.Id == diagnosticId); diff --git a/ModernUO.Serialization.Generator.Tests/ModernUO.Serialization.Generator.Tests.csproj b/ModernUO.Serialization.Generator.Tests/ModernUO.Serialization.Generator.Tests.csproj index 460956e..946b635 100644 --- a/ModernUO.Serialization.Generator.Tests/ModernUO.Serialization.Generator.Tests.csproj +++ b/ModernUO.Serialization.Generator.Tests/ModernUO.Serialization.Generator.Tests.csproj @@ -29,4 +29,10 @@ + + + + + + diff --git a/ModernUO.Serialization.Generator.Tests/SnapshotTests.cs b/ModernUO.Serialization.Generator.Tests/SnapshotTests.cs new file mode 100644 index 0000000..385c815 --- /dev/null +++ b/ModernUO.Serialization.Generator.Tests/SnapshotTests.cs @@ -0,0 +1,117 @@ +using System.Runtime.CompilerServices; +using System.Text.RegularExpressions; +using Microsoft.CodeAnalysis; +using ModernUO.Serialization.Generator.Tests.Helpers; +using Xunit; + +namespace ModernUO.Serialization.Generator.Tests; + +/// +/// Pins the exact generated output for a corpus of feature fixtures under Snapshots/. +/// Each fixture directory contains an Input.cs, optional {Type}.vN.json migration files, +/// and an Expected/ directory with one file per generated source. A fixture must produce +/// output that compiles and matches its Expected/ files byte for byte. +/// +/// Set UPDATE_SNAPSHOTS=1 to rewrite the Expected/ directories from current output +/// instead of asserting. +/// +/// +public class SnapshotTests +{ + private static string SnapshotsRoot([CallerFilePath] string thisFile = "") => + Path.Combine(Path.GetDirectoryName(thisFile)!, "Snapshots"); + + private static bool UpdateMode => Environment.GetEnvironmentVariable("UPDATE_SNAPSHOTS") == "1"; + + // The emitted header stamps the generator version; normalize it so version bumps do not + // invalidate every snapshot. Line endings are normalized so autocrlf checkouts compare + // equal. + private static string NormalizeVersion(string content) => + Regex.Replace( + content.Replace("\r\n", "\n"), + """(Version: |"ModernUO\.Serialization\.Generator", ")\d+\.\d+\.\d+\.\d+""", + "$1{VERSION}" + ); + + public static TheoryData Fixtures() + { + var data = new TheoryData(); + foreach (var dir in Directory.GetDirectories(SnapshotsRoot())) + { + data.Add(Path.GetFileName(dir)); + } + + return data; + } + + [Theory] + [MemberData(nameof(Fixtures))] + public void Fixture_GeneratesPinnedOutput(string fixture) + { + var fixtureDir = Path.Combine(SnapshotsRoot(), fixture); + var source = File.ReadAllText(Path.Combine(fixtureDir, "Input.cs")); + + var additionalTexts = Directory + .GetFiles(fixtureDir, "*.json") + .Select(path => (Path.GetFileName(path), File.ReadAllText(path))) + .ToList(); + + var (diagnostics, sources, compileErrors) = + SourceGeneratorTestHelper.RunGeneratorAllOutputs(source, additionalTexts); + + var expectedDir = Path.Combine(fixtureDir, "Expected"); + + if (UpdateMode) + { + if (Directory.Exists(expectedDir)) + { + Directory.Delete(expectedDir, true); + } + + Directory.CreateDirectory(expectedDir); + + foreach (var (fileName, content) in sources) + { + File.WriteAllText(Path.Combine(expectedDir, fileName), NormalizeVersion(content)); + } + } + + var errors = diagnostics.Where(d => d.Severity == DiagnosticSeverity.Error).ToList(); + Assert.True(errors.Count == 0, $"Generator errors: {string.Join("\n", errors)}"); + + // A KnownBroken.txt marker documents a defect whose (non-compiling) output is still + // pinned so the fix shows up as a snapshot diff. Remove the marker with the fix. + if (!File.Exists(Path.Combine(fixtureDir, "KnownBroken.txt"))) + { + Assert.True(compileErrors.Length == 0, $"Output does not compile: {string.Join("\n", compileErrors.Take(10))}"); + } + + Assert.True(sources.Length > 0, "Fixture produced no generated sources."); + + if (UpdateMode) + { + return; + } + + Assert.True(Directory.Exists(expectedDir), $"Missing {expectedDir}; run with UPDATE_SNAPSHOTS=1 to create it."); + + var expectedFiles = Directory + .GetFiles(expectedDir) + .Select(Path.GetFileName) + .OrderBy(f => f, StringComparer.Ordinal) + .ToArray(); + + var actualFiles = sources + .Select(s => s.FileName) + .OrderBy(f => f, StringComparer.Ordinal) + .ToArray(); + + Assert.Equal(expectedFiles, actualFiles); + + foreach (var (fileName, content) in sources) + { + var expected = File.ReadAllText(Path.Combine(expectedDir, fileName)).Replace("\r\n", "\n"); + Assert.Equal(expected, NormalizeVersion(content)); + } + } +} diff --git a/ModernUO.Serialization.Generator.Tests/Snapshots/BasicFields/Expected/Server.TestContent.BasicFieldsItem.Serialization.g.cs b/ModernUO.Serialization.Generator.Tests/Snapshots/BasicFields/Expected/Server.TestContent.BasicFieldsItem.Serialization.g.cs new file mode 100644 index 0000000..7ce5196 --- /dev/null +++ b/ModernUO.Serialization.Generator.Tests/Snapshots/BasicFields/Expected/Server.TestContent.BasicFieldsItem.Serialization.g.cs @@ -0,0 +1,373 @@ +// +// This code was generated by the ModernUO Serialization Generator tool. +// Version: {VERSION} +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// + +#pragma warning disable + +namespace Server.TestContent +{ + [System.CodeDom.Compiler.GeneratedCode("ModernUO.Serialization.Generator", "{VERSION}")] + public partial class BasicFieldsItem + { + private const int SerializationVersion = 0; + + public int IntValue + { + get => _intValue; + set + { + if (value != _intValue) + { + _intValue = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Name + { + get => _name; + set + { + if (value != _name) + { + _name = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Interned + { + get => _interned; + set + { + if (value != _interned) + { + _interned = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public bool Active + { + get => _active; + set + { + if (value != _active) + { + _active = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public double Weight + { + get => _weight; + set + { + if (value != _weight) + { + _weight = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public System.DateTime Crafted + { + get => _crafted; + set + { + if (value != _crafted) + { + _crafted = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public System.DateTime LastUsed + { + get => _lastUsed; + set + { + if (value != _lastUsed) + { + _lastUsed = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public System.TimeSpan Duration + { + get => _duration; + set + { + if (value != _duration) + { + _duration = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public System.Guid Identifier + { + get => _identifier; + set + { + if (value != _identifier) + { + _identifier = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public int Encoded + { + get => _encoded; + set + { + if (value != _encoded) + { + _encoded = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public decimal Price + { + get => _price; + set + { + if (value != _price) + { + _price = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public byte Small + { + get => _small; + set + { + if (value != _small) + { + _small = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public sbyte SignedSmall + { + get => _signedSmall; + set + { + if (value != _signedSmall) + { + _signedSmall = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public short ShortValue + { + get => _shortValue; + set + { + if (value != _shortValue) + { + _shortValue = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public ushort UnsignedShort + { + get => _unsignedShort; + set + { + if (value != _unsignedShort) + { + _unsignedShort = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public uint UnsignedInt + { + get => _unsignedInt; + set + { + if (value != _unsignedInt) + { + _unsignedInt = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public long LongValue + { + get => _longValue; + set + { + if (value != _longValue) + { + _longValue = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public ulong UnsignedLong + { + get => _unsignedLong; + set + { + if (value != _unsignedLong) + { + _unsignedLong = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public float FloatValue + { + get => _floatValue; + set + { + if (value != _floatValue) + { + _floatValue = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public int PrivateSet + { + get => _privateSet; + private set + { + if (value != _privateSet) + { + _privateSet = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public BasicFieldsItem(Server.Serial serial) + { + Serial = serial; + } + + public virtual void Serialize(Server.IGenericWriter writer) + { + writer.WriteEncodedInt(SerializationVersion); + + writer.Write(_intValue); + + writer.Write(_name); + + writer.Write(_interned); + + writer.Write(_active); + + writer.Write(_weight); + + writer.Write(_crafted); + + writer.WriteDeltaTime(_lastUsed); + + writer.Write(_duration); + + writer.Write(_identifier); + + writer.WriteEncodedInt(_encoded); + + writer.Write(_price); + + writer.Write(_small); + + writer.Write(_signedSmall); + + writer.Write(_shortValue); + + writer.Write(_unsignedShort); + + writer.Write(_unsignedInt); + + writer.Write(_longValue); + + writer.Write(_unsignedLong); + + writer.Write(_floatValue); + + writer.Write(_privateSet); + } + + public virtual void Deserialize(Server.IGenericReader reader) + { + var version = reader.ReadEncodedInt(); + + _intValue = reader.ReadInt(); + + _name = reader.ReadString(); + + _interned = reader.ReadString(true); + + _active = reader.ReadBool(); + + _weight = reader.ReadDouble(); + + _crafted = reader.ReadDateTime(); + + _lastUsed = reader.ReadDeltaTime(); + + _duration = reader.ReadTimeSpan(); + + _identifier = reader.ReadGuid(); + + _encoded = reader.ReadEncodedInt(); + + _price = reader.ReadDecimal(); + + _small = reader.ReadByte(); + + _signedSmall = reader.ReadSByte(); + + _shortValue = reader.ReadShort(); + + _unsignedShort = reader.ReadUShort(); + + _unsignedInt = reader.ReadUInt(); + + _longValue = reader.ReadLong(); + + _unsignedLong = reader.ReadULong(); + + _floatValue = reader.ReadFloat(); + + _privateSet = reader.ReadInt(); + } + } +} diff --git a/ModernUO.Serialization.Generator.Tests/Snapshots/BasicFields/Input.cs b/ModernUO.Serialization.Generator.Tests/Snapshots/BasicFields/Input.cs new file mode 100644 index 0000000..039045b --- /dev/null +++ b/ModernUO.Serialization.Generator.Tests/Snapshots/BasicFields/Input.cs @@ -0,0 +1,78 @@ +using System; +using ModernUO.Serialization; +using Server; + +namespace Server.TestContent +{ + [SerializationGenerator(0)] + public partial class BasicFieldsItem : ISerializable + { + [SerializableField(0)] + private int _intValue; + + [SerializableField(1)] + private string _name; + + [SerializableField(2)] + [InternString] + private string _interned; + + [SerializableField(3)] + private bool _active; + + [SerializableField(4)] + private double _weight; + + [SerializableField(5)] + private DateTime _crafted; + + [SerializableField(6)] + [DeltaDateTime] + private DateTime _lastUsed; + + [SerializableField(7)] + private TimeSpan _duration; + + [SerializableField(8)] + private Guid _identifier; + + [SerializableField(9)] + [EncodedInt] + private int _encoded; + + [SerializableField(10)] + private decimal _price; + + [SerializableField(11)] + private byte _small; + + [SerializableField(12)] + private sbyte _signedSmall; + + [SerializableField(13)] + private short _shortValue; + + [SerializableField(14)] + private ushort _unsignedShort; + + [SerializableField(15)] + private uint _unsignedInt; + + [SerializableField(16)] + private long _longValue; + + [SerializableField(17)] + private ulong _unsignedLong; + + [SerializableField(18)] + private float _floatValue; + + [SerializableField(19, setter: "private")] + private int _privateSet; + + public DateTime Created { get; set; } + public Serial Serial { get; } + public bool Deleted => false; + public void Delete() { } + } +} diff --git a/ModernUO.Serialization.Generator.Tests/Snapshots/Collections/Expected/Server.TestContent.CollectionsItem.Serialization.g.cs b/ModernUO.Serialization.Generator.Tests/Snapshots/Collections/Expected/Server.TestContent.CollectionsItem.Serialization.g.cs new file mode 100644 index 0000000..e41debb --- /dev/null +++ b/ModernUO.Serialization.Generator.Tests/Snapshots/Collections/Expected/Server.TestContent.CollectionsItem.Serialization.g.cs @@ -0,0 +1,247 @@ +// +// This code was generated by the ModernUO Serialization Generator tool. +// Version: {VERSION} +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// + +#pragma warning disable + +namespace Server.TestContent +{ + [System.CodeDom.Compiler.GeneratedCode("ModernUO.Serialization.Generator", "{VERSION}")] + public partial class CollectionsItem + { + private const int SerializationVersion = 0; + + public int[] Levels + { + get => _levels; + set + { + if (value != _levels) + { + _levels = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + + public void ClearLevels() + { + Levels = System.Array.Empty(); + Server.ISerializableExtensions.MarkDirty(this); + } + + public System.Collections.Generic.List Charges + { + get => _charges; + set + { + if (value != _charges) + { + _charges = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public void AddToCharges(int value) + { + Charges.Add(value); + Server.ISerializableExtensions.MarkDirty(this); + } + + public void RemoveFromCharges(int value) + { + Charges.Remove(value); + Server.ISerializableExtensions.MarkDirty(this); + } + + public void InsertIntoCharges(int index, int value) + { + Charges.Insert(index, value); + Server.ISerializableExtensions.MarkDirty(this); + } + + public void RemoveFromChargesAt(int index) + { + Charges.RemoveAt(index); + Server.ISerializableExtensions.MarkDirty(this); + } + + public void ClearCharges() + { + Charges.Clear(); + Server.ISerializableExtensions.MarkDirty(this); + } + + public System.Collections.Generic.HashSet Keywords + { + get => _keywords; + set + { + if (value != _keywords) + { + _keywords = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public void AddToKeywords(string value) + { + Keywords.Add(value); + Server.ISerializableExtensions.MarkDirty(this); + } + + public void RemoveFromKeywords(string value) + { + Keywords.Remove(value); + Server.ISerializableExtensions.MarkDirty(this); + } + + + public void ClearKeywords() + { + Keywords.Clear(); + Server.ISerializableExtensions.MarkDirty(this); + } + + public System.Collections.Generic.Dictionary Labels + { + get => _labels; + set + { + if (value != _labels) + { + _labels = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public void AddToLabels(int key, string value) + { + Labels.Add(key, value); + Server.ISerializableExtensions.MarkDirty(this); + } + + public void RemoveFromLabels(int key) + { + Labels.Remove(key); + Server.ISerializableExtensions.MarkDirty(this); + } + + public void ReplaceInLabels(int key, string value) + { + Labels[key] = value; + Server.ISerializableExtensions.MarkDirty(this); + } + + public void ClearLabels() + { + Labels.Clear(); + Server.ISerializableExtensions.MarkDirty(this); + } + + public CollectionsItem(Server.Serial serial) + { + Serial = serial; + } + + public virtual void Serialize(Server.IGenericWriter writer) + { + writer.WriteEncodedInt(SerializationVersion); + + var _levelsLength = _levels?.Length ?? 0; + writer.WriteEncodedInt(_levelsLength); + for (var _levelsIndex = 0; _levelsIndex < _levelsLength; _levelsIndex++) + { + var _levelsEntry = _levels![_levelsIndex]; + writer.Write(_levelsEntry); + } + + var _chargesCount = _charges?.Count ?? 0; + writer.WriteEncodedInt(_chargesCount); + if (_chargesCount > 0) + { + foreach (var _chargesEntry in _charges!) + { + writer.Write(_chargesEntry); + } + } + + var _keywordsCount = _keywords?.Count ?? 0; + writer.WriteEncodedInt(_keywordsCount); + if (_keywordsCount > 0) + { + foreach (var _keywordsEntry in _keywords!) + { + writer.Write(_keywordsEntry); + } + } + + var _labelsCount = _labels?.Count ?? 0; + writer.WriteEncodedInt(_labelsCount); + if (_labelsCount > 0) + { + foreach (var (_labelsKey, _labelsValue) in _labels!) + { + writer.Write(_labelsKey); + writer.Write(_labelsValue); + } + } + } + + public virtual void Deserialize(Server.IGenericReader reader) + { + var version = reader.ReadEncodedInt(); + + _levels = new int[reader.ReadEncodedInt()]; + for (var _levelsIndex = 0; _levelsIndex < _levels.Length; _levelsIndex++) + { + var _levelsEntry = _levels![_levelsIndex]; + _levelsEntry = reader.ReadInt(); + _levels![_levelsIndex] = _levelsEntry; + } + + int _chargesEntry; + var _chargesCount = reader.ReadEncodedInt(); + _charges = new System.Collections.Generic.List(_chargesCount); + for (var _chargesIndex = 0; _chargesIndex < _chargesCount; _chargesIndex++) + { + _chargesEntry = reader.ReadInt(); + _charges.Add(_chargesEntry); + } + + string _keywordsEntry; + var _keywordsCount = reader.ReadEncodedInt(); + _keywords = new System.Collections.Generic.HashSet(_keywordsCount); + for (var _keywordsIndex = 0; _keywordsIndex < _keywordsCount; _keywordsIndex++) + { + _keywordsEntry = reader.ReadString(); + if (typeof(string).IsValueType || _keywordsEntry != default) + { + _keywords.Add(_keywordsEntry); + } + } + + int _labelsKey; + string _labelsValue; + var _labelsCount = reader.ReadEncodedInt(); + _labels = new System.Collections.Generic.Dictionary(_labelsCount); + for (var _labelsIndex = 0; _labelsIndex < _labelsCount; _labelsIndex++) + { + _labelsKey = reader.ReadInt(); + _labelsValue = reader.ReadString(); + if (typeof(int).IsValueType || _labelsKey != default) + { + _labels.Add(_labelsKey, _labelsValue); + } + } + } + } +} diff --git a/ModernUO.Serialization.Generator.Tests/Snapshots/Collections/Input.cs b/ModernUO.Serialization.Generator.Tests/Snapshots/Collections/Input.cs new file mode 100644 index 0000000..d2176ff --- /dev/null +++ b/ModernUO.Serialization.Generator.Tests/Snapshots/Collections/Input.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using ModernUO.Serialization; +using Server; + +namespace Server.TestContent +{ + [SerializationGenerator(0)] + public partial class CollectionsItem : ISerializable + { + [SerializableField(0)] + private int[] _levels; + + [SerializableField(1)] + private List _charges; + + [SerializableField(2)] + private HashSet _keywords; + + [SerializableField(3)] + private Dictionary _labels; + + public DateTime Created { get; set; } + public Serial Serial { get; } + public bool Deleted => false; + public void Delete() { } + } +} diff --git a/ModernUO.Serialization.Generator.Tests/Snapshots/Enums/Expected/Server.TestContent.EnumsItem.Serialization.g.cs b/ModernUO.Serialization.Generator.Tests/Snapshots/Enums/Expected/Server.TestContent.EnumsItem.Serialization.g.cs new file mode 100644 index 0000000..e24f80a --- /dev/null +++ b/ModernUO.Serialization.Generator.Tests/Snapshots/Enums/Expected/Server.TestContent.EnumsItem.Serialization.g.cs @@ -0,0 +1,67 @@ +// +// This code was generated by the ModernUO Serialization Generator tool. +// Version: {VERSION} +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// + +#pragma warning disable + +namespace Server.TestContent +{ + [System.CodeDom.Compiler.GeneratedCode("ModernUO.Serialization.Generator", "{VERSION}")] + public partial class EnumsItem + { + private const int SerializationVersion = 0; + + public Server.TestContent.ItemQuality Quality + { + get => _quality; + set + { + if (value != _quality) + { + _quality = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public Server.TestContent.ItemTraits Traits + { + get => _traits; + set + { + if (value != _traits) + { + _traits = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public EnumsItem(Server.Serial serial) + { + Serial = serial; + } + + public virtual void Serialize(Server.IGenericWriter writer) + { + writer.WriteEncodedInt(SerializationVersion); + + writer.WriteEnum(_quality); + + writer.WriteEnum(_traits); + } + + public virtual void Deserialize(Server.IGenericReader reader) + { + var version = reader.ReadEncodedInt(); + + _quality = reader.ReadEnum(); + + _traits = reader.ReadEnum(); + } + } +} diff --git a/ModernUO.Serialization.Generator.Tests/Snapshots/Enums/Input.cs b/ModernUO.Serialization.Generator.Tests/Snapshots/Enums/Input.cs new file mode 100644 index 0000000..877a54c --- /dev/null +++ b/ModernUO.Serialization.Generator.Tests/Snapshots/Enums/Input.cs @@ -0,0 +1,37 @@ +using System; +using ModernUO.Serialization; +using Server; + +namespace Server.TestContent +{ + public enum ItemQuality + { + Low, + Regular, + Exceptional + } + + [Flags] + public enum ItemTraits + { + None = 0x0, + Cursed = 0x1, + Blessed = 0x2, + Insured = 0x4 + } + + [SerializationGenerator(0)] + public partial class EnumsItem : ISerializable + { + [SerializableField(0)] + private ItemQuality _quality; + + [SerializableField(1)] + private ItemTraits _traits; + + public DateTime Created { get; set; } + public Serial Serial { get; } + public bool Deleted => false; + public void Delete() { } + } +} diff --git a/ModernUO.Serialization.Generator.Tests/Snapshots/FieldModifiers/Expected/Server.TestContent.FieldModifiersItem.Serialization.g.cs b/ModernUO.Serialization.Generator.Tests/Snapshots/FieldModifiers/Expected/Server.TestContent.FieldModifiersItem.Serialization.g.cs new file mode 100644 index 0000000..bebd768 --- /dev/null +++ b/ModernUO.Serialization.Generator.Tests/Snapshots/FieldModifiers/Expected/Server.TestContent.FieldModifiersItem.Serialization.g.cs @@ -0,0 +1,133 @@ +// +// This code was generated by the ModernUO Serialization Generator tool. +// Version: {VERSION} +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// + +#pragma warning disable + +namespace Server.TestContent +{ + [System.CodeDom.Compiler.GeneratedCode("ModernUO.Serialization.Generator", "{VERSION}")] + public partial class FieldModifiersItem + { + private const int SerializationVersion = 0; + + public string Description + { + get => _description; + set + { + if (value != _description) + { + _description = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public System.Collections.Generic.Dictionary Entries + { + get => _entries; + set + { + if (value != _entries) + { + _entries = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public void AddToEntries(int key, string value) + { + Entries.Add(key, value); + Server.ISerializableExtensions.MarkDirty(this); + } + + public void RemoveFromEntries(int key) + { + Entries.Remove(key); + Server.ISerializableExtensions.MarkDirty(this); + } + + public void ReplaceInEntries(int key, string value) + { + Entries[key] = value; + Server.ISerializableExtensions.MarkDirty(this); + } + + public void ClearEntries() + { + Entries.Clear(); + Server.ISerializableExtensions.MarkDirty(this); + } + + public int Level + { + get => _level; + set + { + var oldValue = _level; + if (value != _level) + { + _level = value; + Server.ISerializableExtensions.MarkDirty(this); + InvalidateProperties(); + OnLevelChanged(oldValue, value); + } + } + } + + public FieldModifiersItem(Server.Serial serial) + { + Serial = serial; + } + + public virtual void Serialize(Server.IGenericWriter writer) + { + writer.WriteEncodedInt(SerializationVersion); + + writer.Write(_description); + + _entries?.Tidy(); + var _entriesCount = _entries?.Count ?? 0; + writer.WriteEncodedInt(_entriesCount); + if (_entriesCount > 0) + { + foreach (var (_entriesKey, _entriesValue) in _entries!) + { + writer.Write(_entriesKey); + writer.Write(_entriesValue); + } + } + + writer.Write(_level); + } + + public virtual void Deserialize(Server.IGenericReader reader) + { + var version = reader.ReadEncodedInt(); + + _description = reader.ReadString(); + + int _entriesKey; + string _entriesValue; + var _entriesCount = reader.ReadEncodedInt(); + _entries = new System.Collections.Generic.Dictionary(_entriesCount); + for (var _entriesIndex = 0; _entriesIndex < _entriesCount; _entriesIndex++) + { + _entriesKey = reader.ReadInt(); + _entriesValue = reader.ReadString(); + if (typeof(int).IsValueType || _entriesKey != default) + { + _entries.Add(_entriesKey, _entriesValue); + } + } + + _level = reader.ReadInt(); + } + } +} diff --git a/ModernUO.Serialization.Generator.Tests/Snapshots/FieldModifiers/Input.cs b/ModernUO.Serialization.Generator.Tests/Snapshots/FieldModifiers/Input.cs new file mode 100644 index 0000000..b2a4d0e --- /dev/null +++ b/ModernUO.Serialization.Generator.Tests/Snapshots/FieldModifiers/Input.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using ModernUO.Serialization; +using Server; + +namespace Server.TestContent +{ + [SerializationGenerator(0)] + public partial class FieldModifiersItem : ISerializable + { + [SerializableField(0)] + [CanBeNull] + private string _description; + + [SerializableField(1)] + [Tidy] + private Dictionary _entries; + + [SerializableField(2)] + [InvalidateProperties] + private int _level; + + [SerializableFieldChanged(2)] + private void OnLevelChanged(int oldValue, int newValue) + { + } + + public DateTime Created { get; set; } + public Serial Serial { get; } + public bool Deleted => false; + public void Delete() { } + public void InvalidateProperties() { } + } +} diff --git a/ModernUO.Serialization.Generator.Tests/Snapshots/Generics/Expected/Server.TestContent.GenericItem`1.Serialization.g.cs b/ModernUO.Serialization.Generator.Tests/Snapshots/Generics/Expected/Server.TestContent.GenericItem`1.Serialization.g.cs new file mode 100644 index 0000000..1f44ba7 --- /dev/null +++ b/ModernUO.Serialization.Generator.Tests/Snapshots/Generics/Expected/Server.TestContent.GenericItem`1.Serialization.g.cs @@ -0,0 +1,50 @@ +// +// This code was generated by the ModernUO Serialization Generator tool. +// Version: {VERSION} +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// + +#pragma warning disable + +namespace Server.TestContent +{ + [System.CodeDom.Compiler.GeneratedCode("ModernUO.Serialization.Generator", "{VERSION}")] + public partial class GenericItem where T : struct + { + private const int SerializationVersion = 0; + + public string Name + { + get => _name; + set + { + if (value != _name) + { + _name = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public GenericItem(Server.Serial serial) + { + Serial = serial; + } + + public virtual void Serialize(Server.IGenericWriter writer) + { + writer.WriteEncodedInt(SerializationVersion); + + writer.Write(_name); + } + + public virtual void Deserialize(Server.IGenericReader reader) + { + var version = reader.ReadEncodedInt(); + + _name = reader.ReadString(); + } + } +} diff --git a/ModernUO.Serialization.Generator.Tests/Snapshots/Generics/Expected/Server.TestContent.PairItem`2.Serialization.g.cs b/ModernUO.Serialization.Generator.Tests/Snapshots/Generics/Expected/Server.TestContent.PairItem`2.Serialization.g.cs new file mode 100644 index 0000000..f186d4e --- /dev/null +++ b/ModernUO.Serialization.Generator.Tests/Snapshots/Generics/Expected/Server.TestContent.PairItem`2.Serialization.g.cs @@ -0,0 +1,50 @@ +// +// This code was generated by the ModernUO Serialization Generator tool. +// Version: {VERSION} +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// + +#pragma warning disable + +namespace Server.TestContent +{ + [System.CodeDom.Compiler.GeneratedCode("ModernUO.Serialization.Generator", "{VERSION}")] + public partial class PairItem where TKey : class where TValue : struct + { + private const int SerializationVersion = 0; + + public string Label + { + get => _label; + set + { + if (value != _label) + { + _label = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public PairItem(Server.Serial serial) + { + Serial = serial; + } + + public virtual void Serialize(Server.IGenericWriter writer) + { + writer.WriteEncodedInt(SerializationVersion); + + writer.Write(_label); + } + + public virtual void Deserialize(Server.IGenericReader reader) + { + var version = reader.ReadEncodedInt(); + + _label = reader.ReadString(); + } + } +} diff --git a/ModernUO.Serialization.Generator.Tests/Snapshots/Generics/Input.cs b/ModernUO.Serialization.Generator.Tests/Snapshots/Generics/Input.cs new file mode 100644 index 0000000..cafd544 --- /dev/null +++ b/ModernUO.Serialization.Generator.Tests/Snapshots/Generics/Input.cs @@ -0,0 +1,32 @@ +using System; +using ModernUO.Serialization; +using Server; + +namespace Server.TestContent +{ + [SerializationGenerator(0)] + public partial class GenericItem : ISerializable where T : struct + { + [SerializableField(0)] + private string _name; + + public DateTime Created { get; set; } + public Serial Serial { get; } + public bool Deleted => false; + public void Delete() { } + } + + [SerializationGenerator(0)] + public partial class PairItem : ISerializable + where TKey : class + where TValue : struct + { + [SerializableField(0)] + private string _label; + + public DateTime Created { get; set; } + public Serial Serial { get; } + public bool Deleted => false; + public void Delete() { } + } +} diff --git a/ModernUO.Serialization.Generator.Tests/Snapshots/Inheritance/Expected/Server.TestContent.BaseItem.Serialization.g.cs b/ModernUO.Serialization.Generator.Tests/Snapshots/Inheritance/Expected/Server.TestContent.BaseItem.Serialization.g.cs new file mode 100644 index 0000000..b191cad --- /dev/null +++ b/ModernUO.Serialization.Generator.Tests/Snapshots/Inheritance/Expected/Server.TestContent.BaseItem.Serialization.g.cs @@ -0,0 +1,50 @@ +// +// This code was generated by the ModernUO Serialization Generator tool. +// Version: {VERSION} +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// + +#pragma warning disable + +namespace Server.TestContent +{ + [System.CodeDom.Compiler.GeneratedCode("ModernUO.Serialization.Generator", "{VERSION}")] + public partial class BaseItem + { + private const int SerializationVersion = 0; + + public string Name + { + get => _name; + set + { + if (value != _name) + { + _name = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public BaseItem(Server.Serial serial) + { + Serial = serial; + } + + public virtual void Serialize(Server.IGenericWriter writer) + { + writer.WriteEncodedInt(SerializationVersion); + + writer.Write(_name); + } + + public virtual void Deserialize(Server.IGenericReader reader) + { + var version = reader.ReadEncodedInt(); + + _name = reader.ReadString(); + } + } +} diff --git a/ModernUO.Serialization.Generator.Tests/Snapshots/Inheritance/Expected/Server.TestContent.DerivedItem.Serialization.g.cs b/ModernUO.Serialization.Generator.Tests/Snapshots/Inheritance/Expected/Server.TestContent.DerivedItem.Serialization.g.cs new file mode 100644 index 0000000..104a499 --- /dev/null +++ b/ModernUO.Serialization.Generator.Tests/Snapshots/Inheritance/Expected/Server.TestContent.DerivedItem.Serialization.g.cs @@ -0,0 +1,53 @@ +// +// This code was generated by the ModernUO Serialization Generator tool. +// Version: {VERSION} +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// + +#pragma warning disable + +namespace Server.TestContent +{ + [System.CodeDom.Compiler.GeneratedCode("ModernUO.Serialization.Generator", "{VERSION}")] + public partial class DerivedItem + { + private const int SerializationVersion = 0; + + public int Bonus + { + get => _bonus; + set + { + if (value != _bonus) + { + _bonus = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public DerivedItem(Server.Serial serial) : base(serial) + { + } + + public override void Serialize(Server.IGenericWriter writer) + { + base.Serialize(writer); + + writer.WriteEncodedInt(SerializationVersion); + + writer.Write(_bonus); + } + + public override void Deserialize(Server.IGenericReader reader) + { + base.Deserialize(reader); + + var version = reader.ReadEncodedInt(); + + _bonus = reader.ReadInt(); + } + } +} diff --git a/ModernUO.Serialization.Generator.Tests/Snapshots/Inheritance/Input.cs b/ModernUO.Serialization.Generator.Tests/Snapshots/Inheritance/Input.cs new file mode 100644 index 0000000..c2c8831 --- /dev/null +++ b/ModernUO.Serialization.Generator.Tests/Snapshots/Inheritance/Input.cs @@ -0,0 +1,25 @@ +using System; +using ModernUO.Serialization; +using Server; + +namespace Server.TestContent +{ + [SerializationGenerator(0)] + public partial class BaseItem : ISerializable + { + [SerializableField(0)] + private string _name; + + public DateTime Created { get; set; } + public Serial Serial { get; } + public bool Deleted => false; + public void Delete() { } + } + + [SerializationGenerator(0)] + public partial class DerivedItem : BaseItem + { + [SerializableField(0)] + private int _bonus; + } +} diff --git a/ModernUO.Serialization.Generator.Tests/Snapshots/ReadonlyFields/Expected/Server.TestContent.ReadonlyItem.Serialization.g.cs b/ModernUO.Serialization.Generator.Tests/Snapshots/ReadonlyFields/Expected/Server.TestContent.ReadonlyItem.Serialization.g.cs new file mode 100644 index 0000000..2eaec02 --- /dev/null +++ b/ModernUO.Serialization.Generator.Tests/Snapshots/ReadonlyFields/Expected/Server.TestContent.ReadonlyItem.Serialization.g.cs @@ -0,0 +1,55 @@ +// +// This code was generated by the ModernUO Serialization Generator tool. +// Version: {VERSION} +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// + +#pragma warning disable + +namespace Server.TestContent +{ + [System.CodeDom.Compiler.GeneratedCode("ModernUO.Serialization.Generator", "{VERSION}")] + public partial class ReadonlyItem + { + private const int SerializationVersion = 0; + + public string Id + { + get => _id; + } + + public string Name + { + get => _name; + set + { + if (value != _name) + { + _name = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public ReadonlyItem(Server.Serial serial) + { + Serial = serial; + } + + public virtual void Serialize(Server.IGenericWriter writer) + { + writer.WriteEncodedInt(SerializationVersion); + + writer.Write(_name); + } + + public virtual void Deserialize(Server.IGenericReader reader) + { + var version = reader.ReadEncodedInt(); + + _name = reader.ReadString(); + } + } +} diff --git a/ModernUO.Serialization.Generator.Tests/Snapshots/ReadonlyFields/Input.cs b/ModernUO.Serialization.Generator.Tests/Snapshots/ReadonlyFields/Input.cs new file mode 100644 index 0000000..eab5004 --- /dev/null +++ b/ModernUO.Serialization.Generator.Tests/Snapshots/ReadonlyFields/Input.cs @@ -0,0 +1,21 @@ +using System; +using ModernUO.Serialization; +using Server; + +namespace Server.TestContent +{ + [SerializationGenerator(0)] + public partial class ReadonlyItem : ISerializable + { + [SerializableField(0)] + private readonly string _id; + + [SerializableField(1)] + private string _name; + + public DateTime Created { get; set; } + public Serial Serial { get; } + public bool Deleted => false; + public void Delete() { } + } +} diff --git a/ModernUO.Serialization.Generator.Tests/Snapshots/SaveFlagsMultiEnum/Expected/Server.TestContent.MultiEnumFlagsItem.Serialization.g.cs b/ModernUO.Serialization.Generator.Tests/Snapshots/SaveFlagsMultiEnum/Expected/Server.TestContent.MultiEnumFlagsItem.Serialization.g.cs new file mode 100644 index 0000000..bc3c046 --- /dev/null +++ b/ModernUO.Serialization.Generator.Tests/Snapshots/SaveFlagsMultiEnum/Expected/Server.TestContent.MultiEnumFlagsItem.Serialization.g.cs @@ -0,0 +1,2014 @@ +// +// This code was generated by the ModernUO Serialization Generator tool. +// Version: {VERSION} +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// + +#pragma warning disable + +namespace Server.TestContent +{ + [System.CodeDom.Compiler.GeneratedCode("ModernUO.Serialization.Generator", "{VERSION}")] + public partial class MultiEnumFlagsItem + { + private const int SerializationVersion = 0; + + public string Field0 + { + get => _field0; + set + { + if (value != _field0) + { + _field0 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field1 + { + get => _field1; + set + { + if (value != _field1) + { + _field1 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field2 + { + get => _field2; + set + { + if (value != _field2) + { + _field2 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field3 + { + get => _field3; + set + { + if (value != _field3) + { + _field3 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field4 + { + get => _field4; + set + { + if (value != _field4) + { + _field4 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field5 + { + get => _field5; + set + { + if (value != _field5) + { + _field5 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field6 + { + get => _field6; + set + { + if (value != _field6) + { + _field6 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field7 + { + get => _field7; + set + { + if (value != _field7) + { + _field7 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field8 + { + get => _field8; + set + { + if (value != _field8) + { + _field8 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field9 + { + get => _field9; + set + { + if (value != _field9) + { + _field9 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field10 + { + get => _field10; + set + { + if (value != _field10) + { + _field10 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field11 + { + get => _field11; + set + { + if (value != _field11) + { + _field11 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field12 + { + get => _field12; + set + { + if (value != _field12) + { + _field12 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field13 + { + get => _field13; + set + { + if (value != _field13) + { + _field13 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field14 + { + get => _field14; + set + { + if (value != _field14) + { + _field14 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field15 + { + get => _field15; + set + { + if (value != _field15) + { + _field15 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field16 + { + get => _field16; + set + { + if (value != _field16) + { + _field16 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field17 + { + get => _field17; + set + { + if (value != _field17) + { + _field17 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field18 + { + get => _field18; + set + { + if (value != _field18) + { + _field18 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field19 + { + get => _field19; + set + { + if (value != _field19) + { + _field19 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field20 + { + get => _field20; + set + { + if (value != _field20) + { + _field20 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field21 + { + get => _field21; + set + { + if (value != _field21) + { + _field21 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field22 + { + get => _field22; + set + { + if (value != _field22) + { + _field22 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field23 + { + get => _field23; + set + { + if (value != _field23) + { + _field23 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field24 + { + get => _field24; + set + { + if (value != _field24) + { + _field24 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field25 + { + get => _field25; + set + { + if (value != _field25) + { + _field25 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field26 + { + get => _field26; + set + { + if (value != _field26) + { + _field26 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field27 + { + get => _field27; + set + { + if (value != _field27) + { + _field27 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field28 + { + get => _field28; + set + { + if (value != _field28) + { + _field28 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field29 + { + get => _field29; + set + { + if (value != _field29) + { + _field29 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field30 + { + get => _field30; + set + { + if (value != _field30) + { + _field30 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field31 + { + get => _field31; + set + { + if (value != _field31) + { + _field31 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field32 + { + get => _field32; + set + { + if (value != _field32) + { + _field32 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field33 + { + get => _field33; + set + { + if (value != _field33) + { + _field33 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field34 + { + get => _field34; + set + { + if (value != _field34) + { + _field34 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field35 + { + get => _field35; + set + { + if (value != _field35) + { + _field35 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field36 + { + get => _field36; + set + { + if (value != _field36) + { + _field36 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field37 + { + get => _field37; + set + { + if (value != _field37) + { + _field37 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field38 + { + get => _field38; + set + { + if (value != _field38) + { + _field38 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field39 + { + get => _field39; + set + { + if (value != _field39) + { + _field39 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field40 + { + get => _field40; + set + { + if (value != _field40) + { + _field40 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field41 + { + get => _field41; + set + { + if (value != _field41) + { + _field41 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field42 + { + get => _field42; + set + { + if (value != _field42) + { + _field42 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field43 + { + get => _field43; + set + { + if (value != _field43) + { + _field43 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field44 + { + get => _field44; + set + { + if (value != _field44) + { + _field44 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field45 + { + get => _field45; + set + { + if (value != _field45) + { + _field45 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field46 + { + get => _field46; + set + { + if (value != _field46) + { + _field46 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field47 + { + get => _field47; + set + { + if (value != _field47) + { + _field47 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field48 + { + get => _field48; + set + { + if (value != _field48) + { + _field48 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field49 + { + get => _field49; + set + { + if (value != _field49) + { + _field49 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field50 + { + get => _field50; + set + { + if (value != _field50) + { + _field50 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field51 + { + get => _field51; + set + { + if (value != _field51) + { + _field51 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field52 + { + get => _field52; + set + { + if (value != _field52) + { + _field52 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field53 + { + get => _field53; + set + { + if (value != _field53) + { + _field53 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field54 + { + get => _field54; + set + { + if (value != _field54) + { + _field54 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field55 + { + get => _field55; + set + { + if (value != _field55) + { + _field55 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field56 + { + get => _field56; + set + { + if (value != _field56) + { + _field56 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field57 + { + get => _field57; + set + { + if (value != _field57) + { + _field57 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field58 + { + get => _field58; + set + { + if (value != _field58) + { + _field58 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field59 + { + get => _field59; + set + { + if (value != _field59) + { + _field59 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field60 + { + get => _field60; + set + { + if (value != _field60) + { + _field60 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field61 + { + get => _field61; + set + { + if (value != _field61) + { + _field61 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field62 + { + get => _field62; + set + { + if (value != _field62) + { + _field62 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field63 + { + get => _field63; + set + { + if (value != _field63) + { + _field63 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field64 + { + get => _field64; + set + { + if (value != _field64) + { + _field64 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field65 + { + get => _field65; + set + { + if (value != _field65) + { + _field65 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field66 + { + get => _field66; + set + { + if (value != _field66) + { + _field66 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field67 + { + get => _field67; + set + { + if (value != _field67) + { + _field67 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field68 + { + get => _field68; + set + { + if (value != _field68) + { + _field68 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field69 + { + get => _field69; + set + { + if (value != _field69) + { + _field69 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public MultiEnumFlagsItem(Server.Serial serial) + { + Serial = serial; + } + + public virtual void Serialize(Server.IGenericWriter writer) + { + writer.WriteEncodedInt(SerializationVersion); + + var saveFlags = SaveFlag.None; + + var saveFlags2 = SaveFlag2.None; + if (ShouldSerializeField0()) + { + saveFlags |= SaveFlag.Field0; + } + if (ShouldSerializeField1()) + { + saveFlags |= SaveFlag.Field1; + } + if (ShouldSerializeField2()) + { + saveFlags |= SaveFlag.Field2; + } + if (ShouldSerializeField3()) + { + saveFlags |= SaveFlag.Field3; + } + if (ShouldSerializeField4()) + { + saveFlags |= SaveFlag.Field4; + } + if (ShouldSerializeField5()) + { + saveFlags |= SaveFlag.Field5; + } + if (ShouldSerializeField6()) + { + saveFlags |= SaveFlag.Field6; + } + if (ShouldSerializeField7()) + { + saveFlags |= SaveFlag.Field7; + } + if (ShouldSerializeField8()) + { + saveFlags |= SaveFlag.Field8; + } + if (ShouldSerializeField9()) + { + saveFlags |= SaveFlag.Field9; + } + if (ShouldSerializeField10()) + { + saveFlags |= SaveFlag.Field10; + } + if (ShouldSerializeField11()) + { + saveFlags |= SaveFlag.Field11; + } + if (ShouldSerializeField12()) + { + saveFlags |= SaveFlag.Field12; + } + if (ShouldSerializeField13()) + { + saveFlags |= SaveFlag.Field13; + } + if (ShouldSerializeField14()) + { + saveFlags |= SaveFlag.Field14; + } + if (ShouldSerializeField15()) + { + saveFlags |= SaveFlag.Field15; + } + if (ShouldSerializeField16()) + { + saveFlags |= SaveFlag.Field16; + } + if (ShouldSerializeField17()) + { + saveFlags |= SaveFlag.Field17; + } + if (ShouldSerializeField18()) + { + saveFlags |= SaveFlag.Field18; + } + if (ShouldSerializeField19()) + { + saveFlags |= SaveFlag.Field19; + } + if (ShouldSerializeField20()) + { + saveFlags |= SaveFlag.Field20; + } + if (ShouldSerializeField21()) + { + saveFlags |= SaveFlag.Field21; + } + if (ShouldSerializeField22()) + { + saveFlags |= SaveFlag.Field22; + } + if (ShouldSerializeField23()) + { + saveFlags |= SaveFlag.Field23; + } + if (ShouldSerializeField24()) + { + saveFlags |= SaveFlag.Field24; + } + if (ShouldSerializeField25()) + { + saveFlags |= SaveFlag.Field25; + } + if (ShouldSerializeField26()) + { + saveFlags |= SaveFlag.Field26; + } + if (ShouldSerializeField27()) + { + saveFlags |= SaveFlag.Field27; + } + if (ShouldSerializeField28()) + { + saveFlags |= SaveFlag.Field28; + } + if (ShouldSerializeField29()) + { + saveFlags |= SaveFlag.Field29; + } + if (ShouldSerializeField30()) + { + saveFlags |= SaveFlag.Field30; + } + if (ShouldSerializeField31()) + { + saveFlags |= SaveFlag.Field31; + } + if (ShouldSerializeField32()) + { + saveFlags |= SaveFlag.Field32; + } + if (ShouldSerializeField33()) + { + saveFlags |= SaveFlag.Field33; + } + if (ShouldSerializeField34()) + { + saveFlags |= SaveFlag.Field34; + } + if (ShouldSerializeField35()) + { + saveFlags |= SaveFlag.Field35; + } + if (ShouldSerializeField36()) + { + saveFlags |= SaveFlag.Field36; + } + if (ShouldSerializeField37()) + { + saveFlags |= SaveFlag.Field37; + } + if (ShouldSerializeField38()) + { + saveFlags |= SaveFlag.Field38; + } + if (ShouldSerializeField39()) + { + saveFlags |= SaveFlag.Field39; + } + if (ShouldSerializeField40()) + { + saveFlags |= SaveFlag.Field40; + } + if (ShouldSerializeField41()) + { + saveFlags |= SaveFlag.Field41; + } + if (ShouldSerializeField42()) + { + saveFlags |= SaveFlag.Field42; + } + if (ShouldSerializeField43()) + { + saveFlags |= SaveFlag.Field43; + } + if (ShouldSerializeField44()) + { + saveFlags |= SaveFlag.Field44; + } + if (ShouldSerializeField45()) + { + saveFlags |= SaveFlag.Field45; + } + if (ShouldSerializeField46()) + { + saveFlags |= SaveFlag.Field46; + } + if (ShouldSerializeField47()) + { + saveFlags |= SaveFlag.Field47; + } + if (ShouldSerializeField48()) + { + saveFlags |= SaveFlag.Field48; + } + if (ShouldSerializeField49()) + { + saveFlags |= SaveFlag.Field49; + } + if (ShouldSerializeField50()) + { + saveFlags |= SaveFlag.Field50; + } + if (ShouldSerializeField51()) + { + saveFlags |= SaveFlag.Field51; + } + if (ShouldSerializeField52()) + { + saveFlags |= SaveFlag.Field52; + } + if (ShouldSerializeField53()) + { + saveFlags |= SaveFlag.Field53; + } + if (ShouldSerializeField54()) + { + saveFlags |= SaveFlag.Field54; + } + if (ShouldSerializeField55()) + { + saveFlags |= SaveFlag.Field55; + } + if (ShouldSerializeField56()) + { + saveFlags |= SaveFlag.Field56; + } + if (ShouldSerializeField57()) + { + saveFlags |= SaveFlag.Field57; + } + if (ShouldSerializeField58()) + { + saveFlags |= SaveFlag.Field58; + } + if (ShouldSerializeField59()) + { + saveFlags |= SaveFlag.Field59; + } + if (ShouldSerializeField60()) + { + saveFlags |= SaveFlag.Field60; + } + if (ShouldSerializeField61()) + { + saveFlags |= SaveFlag.Field61; + } + if (ShouldSerializeField62()) + { + saveFlags |= SaveFlag.Field62; + } + if (ShouldSerializeField63()) + { + saveFlags |= SaveFlag.Field63; + } + if (ShouldSerializeField64()) + { + saveFlags2 |= SaveFlag2.Field64; + } + if (ShouldSerializeField65()) + { + saveFlags2 |= SaveFlag2.Field65; + } + if (ShouldSerializeField66()) + { + saveFlags2 |= SaveFlag2.Field66; + } + if (ShouldSerializeField67()) + { + saveFlags2 |= SaveFlag2.Field67; + } + if (ShouldSerializeField68()) + { + saveFlags2 |= SaveFlag2.Field68; + } + if (ShouldSerializeField69()) + { + saveFlags2 |= SaveFlag2.Field69; + } + writer.WriteEnum(saveFlags); + writer.WriteEnum(saveFlags2); + + if ((saveFlags & SaveFlag.Field0) != 0) + { + writer.Write(_field0); + } + + if ((saveFlags & SaveFlag.Field1) != 0) + { + writer.Write(_field1); + } + + if ((saveFlags & SaveFlag.Field2) != 0) + { + writer.Write(_field2); + } + + if ((saveFlags & SaveFlag.Field3) != 0) + { + writer.Write(_field3); + } + + if ((saveFlags & SaveFlag.Field4) != 0) + { + writer.Write(_field4); + } + + if ((saveFlags & SaveFlag.Field5) != 0) + { + writer.Write(_field5); + } + + if ((saveFlags & SaveFlag.Field6) != 0) + { + writer.Write(_field6); + } + + if ((saveFlags & SaveFlag.Field7) != 0) + { + writer.Write(_field7); + } + + if ((saveFlags & SaveFlag.Field8) != 0) + { + writer.Write(_field8); + } + + if ((saveFlags & SaveFlag.Field9) != 0) + { + writer.Write(_field9); + } + + if ((saveFlags & SaveFlag.Field10) != 0) + { + writer.Write(_field10); + } + + if ((saveFlags & SaveFlag.Field11) != 0) + { + writer.Write(_field11); + } + + if ((saveFlags & SaveFlag.Field12) != 0) + { + writer.Write(_field12); + } + + if ((saveFlags & SaveFlag.Field13) != 0) + { + writer.Write(_field13); + } + + if ((saveFlags & SaveFlag.Field14) != 0) + { + writer.Write(_field14); + } + + if ((saveFlags & SaveFlag.Field15) != 0) + { + writer.Write(_field15); + } + + if ((saveFlags & SaveFlag.Field16) != 0) + { + writer.Write(_field16); + } + + if ((saveFlags & SaveFlag.Field17) != 0) + { + writer.Write(_field17); + } + + if ((saveFlags & SaveFlag.Field18) != 0) + { + writer.Write(_field18); + } + + if ((saveFlags & SaveFlag.Field19) != 0) + { + writer.Write(_field19); + } + + if ((saveFlags & SaveFlag.Field20) != 0) + { + writer.Write(_field20); + } + + if ((saveFlags & SaveFlag.Field21) != 0) + { + writer.Write(_field21); + } + + if ((saveFlags & SaveFlag.Field22) != 0) + { + writer.Write(_field22); + } + + if ((saveFlags & SaveFlag.Field23) != 0) + { + writer.Write(_field23); + } + + if ((saveFlags & SaveFlag.Field24) != 0) + { + writer.Write(_field24); + } + + if ((saveFlags & SaveFlag.Field25) != 0) + { + writer.Write(_field25); + } + + if ((saveFlags & SaveFlag.Field26) != 0) + { + writer.Write(_field26); + } + + if ((saveFlags & SaveFlag.Field27) != 0) + { + writer.Write(_field27); + } + + if ((saveFlags & SaveFlag.Field28) != 0) + { + writer.Write(_field28); + } + + if ((saveFlags & SaveFlag.Field29) != 0) + { + writer.Write(_field29); + } + + if ((saveFlags & SaveFlag.Field30) != 0) + { + writer.Write(_field30); + } + + if ((saveFlags & SaveFlag.Field31) != 0) + { + writer.Write(_field31); + } + + if ((saveFlags & SaveFlag.Field32) != 0) + { + writer.Write(_field32); + } + + if ((saveFlags & SaveFlag.Field33) != 0) + { + writer.Write(_field33); + } + + if ((saveFlags & SaveFlag.Field34) != 0) + { + writer.Write(_field34); + } + + if ((saveFlags & SaveFlag.Field35) != 0) + { + writer.Write(_field35); + } + + if ((saveFlags & SaveFlag.Field36) != 0) + { + writer.Write(_field36); + } + + if ((saveFlags & SaveFlag.Field37) != 0) + { + writer.Write(_field37); + } + + if ((saveFlags & SaveFlag.Field38) != 0) + { + writer.Write(_field38); + } + + if ((saveFlags & SaveFlag.Field39) != 0) + { + writer.Write(_field39); + } + + if ((saveFlags & SaveFlag.Field40) != 0) + { + writer.Write(_field40); + } + + if ((saveFlags & SaveFlag.Field41) != 0) + { + writer.Write(_field41); + } + + if ((saveFlags & SaveFlag.Field42) != 0) + { + writer.Write(_field42); + } + + if ((saveFlags & SaveFlag.Field43) != 0) + { + writer.Write(_field43); + } + + if ((saveFlags & SaveFlag.Field44) != 0) + { + writer.Write(_field44); + } + + if ((saveFlags & SaveFlag.Field45) != 0) + { + writer.Write(_field45); + } + + if ((saveFlags & SaveFlag.Field46) != 0) + { + writer.Write(_field46); + } + + if ((saveFlags & SaveFlag.Field47) != 0) + { + writer.Write(_field47); + } + + if ((saveFlags & SaveFlag.Field48) != 0) + { + writer.Write(_field48); + } + + if ((saveFlags & SaveFlag.Field49) != 0) + { + writer.Write(_field49); + } + + if ((saveFlags & SaveFlag.Field50) != 0) + { + writer.Write(_field50); + } + + if ((saveFlags & SaveFlag.Field51) != 0) + { + writer.Write(_field51); + } + + if ((saveFlags & SaveFlag.Field52) != 0) + { + writer.Write(_field52); + } + + if ((saveFlags & SaveFlag.Field53) != 0) + { + writer.Write(_field53); + } + + if ((saveFlags & SaveFlag.Field54) != 0) + { + writer.Write(_field54); + } + + if ((saveFlags & SaveFlag.Field55) != 0) + { + writer.Write(_field55); + } + + if ((saveFlags & SaveFlag.Field56) != 0) + { + writer.Write(_field56); + } + + if ((saveFlags & SaveFlag.Field57) != 0) + { + writer.Write(_field57); + } + + if ((saveFlags & SaveFlag.Field58) != 0) + { + writer.Write(_field58); + } + + if ((saveFlags & SaveFlag.Field59) != 0) + { + writer.Write(_field59); + } + + if ((saveFlags & SaveFlag.Field60) != 0) + { + writer.Write(_field60); + } + + if ((saveFlags & SaveFlag.Field61) != 0) + { + writer.Write(_field61); + } + + if ((saveFlags & SaveFlag.Field62) != 0) + { + writer.Write(_field62); + } + + if ((saveFlags & SaveFlag.Field63) != 0) + { + writer.Write(_field63); + } + + if ((saveFlags2 & SaveFlag2.Field64) != 0) + { + writer.Write(_field64); + } + + if ((saveFlags2 & SaveFlag2.Field65) != 0) + { + writer.Write(_field65); + } + + if ((saveFlags2 & SaveFlag2.Field66) != 0) + { + writer.Write(_field66); + } + + if ((saveFlags2 & SaveFlag2.Field67) != 0) + { + writer.Write(_field67); + } + + if ((saveFlags2 & SaveFlag2.Field68) != 0) + { + writer.Write(_field68); + } + + if ((saveFlags2 & SaveFlag2.Field69) != 0) + { + writer.Write(_field69); + } + } + + public virtual void Deserialize(Server.IGenericReader reader) + { + var version = reader.ReadEncodedInt(); + + var saveFlags = reader.ReadEnum(); + var saveFlags2 = reader.ReadEnum(); + + if ((saveFlags & SaveFlag.Field0) != 0) + { + _field0 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field1) != 0) + { + _field1 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field2) != 0) + { + _field2 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field3) != 0) + { + _field3 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field4) != 0) + { + _field4 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field5) != 0) + { + _field5 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field6) != 0) + { + _field6 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field7) != 0) + { + _field7 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field8) != 0) + { + _field8 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field9) != 0) + { + _field9 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field10) != 0) + { + _field10 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field11) != 0) + { + _field11 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field12) != 0) + { + _field12 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field13) != 0) + { + _field13 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field14) != 0) + { + _field14 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field15) != 0) + { + _field15 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field16) != 0) + { + _field16 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field17) != 0) + { + _field17 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field18) != 0) + { + _field18 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field19) != 0) + { + _field19 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field20) != 0) + { + _field20 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field21) != 0) + { + _field21 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field22) != 0) + { + _field22 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field23) != 0) + { + _field23 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field24) != 0) + { + _field24 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field25) != 0) + { + _field25 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field26) != 0) + { + _field26 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field27) != 0) + { + _field27 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field28) != 0) + { + _field28 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field29) != 0) + { + _field29 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field30) != 0) + { + _field30 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field31) != 0) + { + _field31 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field32) != 0) + { + _field32 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field33) != 0) + { + _field33 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field34) != 0) + { + _field34 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field35) != 0) + { + _field35 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field36) != 0) + { + _field36 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field37) != 0) + { + _field37 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field38) != 0) + { + _field38 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field39) != 0) + { + _field39 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field40) != 0) + { + _field40 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field41) != 0) + { + _field41 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field42) != 0) + { + _field42 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field43) != 0) + { + _field43 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field44) != 0) + { + _field44 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field45) != 0) + { + _field45 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field46) != 0) + { + _field46 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field47) != 0) + { + _field47 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field48) != 0) + { + _field48 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field49) != 0) + { + _field49 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field50) != 0) + { + _field50 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field51) != 0) + { + _field51 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field52) != 0) + { + _field52 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field53) != 0) + { + _field53 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field54) != 0) + { + _field54 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field55) != 0) + { + _field55 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field56) != 0) + { + _field56 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field57) != 0) + { + _field57 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field58) != 0) + { + _field58 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field59) != 0) + { + _field59 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field60) != 0) + { + _field60 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field61) != 0) + { + _field61 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field62) != 0) + { + _field62 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field63) != 0) + { + _field63 = reader.ReadString(); + } + + if ((saveFlags2 & SaveFlag2.Field64) != 0) + { + _field64 = reader.ReadString(); + } + + if ((saveFlags2 & SaveFlag2.Field65) != 0) + { + _field65 = reader.ReadString(); + } + + if ((saveFlags2 & SaveFlag2.Field66) != 0) + { + _field66 = reader.ReadString(); + } + + if ((saveFlags2 & SaveFlag2.Field67) != 0) + { + _field67 = reader.ReadString(); + } + + if ((saveFlags2 & SaveFlag2.Field68) != 0) + { + _field68 = reader.ReadString(); + } + + if ((saveFlags2 & SaveFlag2.Field69) != 0) + { + _field69 = reader.ReadString(); + } + } + + [System.Flags] + private enum SaveFlag : ulong + { + None = 0x0000000000000000, + Field0 = 0x0000000000000001, + Field1 = 0x0000000000000002, + Field2 = 0x0000000000000004, + Field3 = 0x0000000000000008, + Field4 = 0x0000000000000010, + Field5 = 0x0000000000000020, + Field6 = 0x0000000000000040, + Field7 = 0x0000000000000080, + Field8 = 0x0000000000000100, + Field9 = 0x0000000000000200, + Field10 = 0x0000000000000400, + Field11 = 0x0000000000000800, + Field12 = 0x0000000000001000, + Field13 = 0x0000000000002000, + Field14 = 0x0000000000004000, + Field15 = 0x0000000000008000, + Field16 = 0x0000000000010000, + Field17 = 0x0000000000020000, + Field18 = 0x0000000000040000, + Field19 = 0x0000000000080000, + Field20 = 0x0000000000100000, + Field21 = 0x0000000000200000, + Field22 = 0x0000000000400000, + Field23 = 0x0000000000800000, + Field24 = 0x0000000001000000, + Field25 = 0x0000000002000000, + Field26 = 0x0000000004000000, + Field27 = 0x0000000008000000, + Field28 = 0x0000000010000000, + Field29 = 0x0000000020000000, + Field30 = 0x0000000040000000, + Field31 = 0x0000000080000000, + Field32 = 0x0000000100000000, + Field33 = 0x0000000200000000, + Field34 = 0x0000000400000000, + Field35 = 0x0000000800000000, + Field36 = 0x0000001000000000, + Field37 = 0x0000002000000000, + Field38 = 0x0000004000000000, + Field39 = 0x0000008000000000, + Field40 = 0x0000010000000000, + Field41 = 0x0000020000000000, + Field42 = 0x0000040000000000, + Field43 = 0x0000080000000000, + Field44 = 0x0000100000000000, + Field45 = 0x0000200000000000, + Field46 = 0x0000400000000000, + Field47 = 0x0000800000000000, + Field48 = 0x0001000000000000, + Field49 = 0x0002000000000000, + Field50 = 0x0004000000000000, + Field51 = 0x0008000000000000, + Field52 = 0x0010000000000000, + Field53 = 0x0020000000000000, + Field54 = 0x0040000000000000, + Field55 = 0x0080000000000000, + Field56 = 0x0100000000000000, + Field57 = 0x0200000000000000, + Field58 = 0x0400000000000000, + Field59 = 0x0800000000000000, + Field60 = 0x1000000000000000, + Field61 = 0x2000000000000000, + Field62 = 0x4000000000000000, + Field63 = 0x8000000000000000, + } + + [System.Flags] + private enum SaveFlag2 : ulong + { + None = 0x0000000000000000, + Field64 = 0x0000000000000001, + Field65 = 0x0000000000000002, + Field66 = 0x0000000000000004, + Field67 = 0x0000000000000008, + Field68 = 0x0000000000000010, + Field69 = 0x0000000000000020, + } + } +} diff --git a/ModernUO.Serialization.Generator.Tests/Snapshots/SaveFlagsMultiEnum/Input.cs b/ModernUO.Serialization.Generator.Tests/Snapshots/SaveFlagsMultiEnum/Input.cs new file mode 100644 index 0000000..c14d286 --- /dev/null +++ b/ModernUO.Serialization.Generator.Tests/Snapshots/SaveFlagsMultiEnum/Input.cs @@ -0,0 +1,435 @@ +using System; +using ModernUO.Serialization; +using Server; + +namespace Server.TestContent +{ + [SerializationGenerator(0)] + public partial class MultiEnumFlagsItem : ISerializable + { + [SerializableField(0)] + private string _field0; + + [SerializableFieldSaveFlag(0)] + private bool ShouldSerializeField0() => _field0 != null; + + [SerializableField(1)] + private string _field1; + + [SerializableFieldSaveFlag(1)] + private bool ShouldSerializeField1() => _field1 != null; + + [SerializableField(2)] + private string _field2; + + [SerializableFieldSaveFlag(2)] + private bool ShouldSerializeField2() => _field2 != null; + + [SerializableField(3)] + private string _field3; + + [SerializableFieldSaveFlag(3)] + private bool ShouldSerializeField3() => _field3 != null; + + [SerializableField(4)] + private string _field4; + + [SerializableFieldSaveFlag(4)] + private bool ShouldSerializeField4() => _field4 != null; + + [SerializableField(5)] + private string _field5; + + [SerializableFieldSaveFlag(5)] + private bool ShouldSerializeField5() => _field5 != null; + + [SerializableField(6)] + private string _field6; + + [SerializableFieldSaveFlag(6)] + private bool ShouldSerializeField6() => _field6 != null; + + [SerializableField(7)] + private string _field7; + + [SerializableFieldSaveFlag(7)] + private bool ShouldSerializeField7() => _field7 != null; + + [SerializableField(8)] + private string _field8; + + [SerializableFieldSaveFlag(8)] + private bool ShouldSerializeField8() => _field8 != null; + + [SerializableField(9)] + private string _field9; + + [SerializableFieldSaveFlag(9)] + private bool ShouldSerializeField9() => _field9 != null; + + [SerializableField(10)] + private string _field10; + + [SerializableFieldSaveFlag(10)] + private bool ShouldSerializeField10() => _field10 != null; + + [SerializableField(11)] + private string _field11; + + [SerializableFieldSaveFlag(11)] + private bool ShouldSerializeField11() => _field11 != null; + + [SerializableField(12)] + private string _field12; + + [SerializableFieldSaveFlag(12)] + private bool ShouldSerializeField12() => _field12 != null; + + [SerializableField(13)] + private string _field13; + + [SerializableFieldSaveFlag(13)] + private bool ShouldSerializeField13() => _field13 != null; + + [SerializableField(14)] + private string _field14; + + [SerializableFieldSaveFlag(14)] + private bool ShouldSerializeField14() => _field14 != null; + + [SerializableField(15)] + private string _field15; + + [SerializableFieldSaveFlag(15)] + private bool ShouldSerializeField15() => _field15 != null; + + [SerializableField(16)] + private string _field16; + + [SerializableFieldSaveFlag(16)] + private bool ShouldSerializeField16() => _field16 != null; + + [SerializableField(17)] + private string _field17; + + [SerializableFieldSaveFlag(17)] + private bool ShouldSerializeField17() => _field17 != null; + + [SerializableField(18)] + private string _field18; + + [SerializableFieldSaveFlag(18)] + private bool ShouldSerializeField18() => _field18 != null; + + [SerializableField(19)] + private string _field19; + + [SerializableFieldSaveFlag(19)] + private bool ShouldSerializeField19() => _field19 != null; + + [SerializableField(20)] + private string _field20; + + [SerializableFieldSaveFlag(20)] + private bool ShouldSerializeField20() => _field20 != null; + + [SerializableField(21)] + private string _field21; + + [SerializableFieldSaveFlag(21)] + private bool ShouldSerializeField21() => _field21 != null; + + [SerializableField(22)] + private string _field22; + + [SerializableFieldSaveFlag(22)] + private bool ShouldSerializeField22() => _field22 != null; + + [SerializableField(23)] + private string _field23; + + [SerializableFieldSaveFlag(23)] + private bool ShouldSerializeField23() => _field23 != null; + + [SerializableField(24)] + private string _field24; + + [SerializableFieldSaveFlag(24)] + private bool ShouldSerializeField24() => _field24 != null; + + [SerializableField(25)] + private string _field25; + + [SerializableFieldSaveFlag(25)] + private bool ShouldSerializeField25() => _field25 != null; + + [SerializableField(26)] + private string _field26; + + [SerializableFieldSaveFlag(26)] + private bool ShouldSerializeField26() => _field26 != null; + + [SerializableField(27)] + private string _field27; + + [SerializableFieldSaveFlag(27)] + private bool ShouldSerializeField27() => _field27 != null; + + [SerializableField(28)] + private string _field28; + + [SerializableFieldSaveFlag(28)] + private bool ShouldSerializeField28() => _field28 != null; + + [SerializableField(29)] + private string _field29; + + [SerializableFieldSaveFlag(29)] + private bool ShouldSerializeField29() => _field29 != null; + + [SerializableField(30)] + private string _field30; + + [SerializableFieldSaveFlag(30)] + private bool ShouldSerializeField30() => _field30 != null; + + [SerializableField(31)] + private string _field31; + + [SerializableFieldSaveFlag(31)] + private bool ShouldSerializeField31() => _field31 != null; + + [SerializableField(32)] + private string _field32; + + [SerializableFieldSaveFlag(32)] + private bool ShouldSerializeField32() => _field32 != null; + + [SerializableField(33)] + private string _field33; + + [SerializableFieldSaveFlag(33)] + private bool ShouldSerializeField33() => _field33 != null; + + [SerializableField(34)] + private string _field34; + + [SerializableFieldSaveFlag(34)] + private bool ShouldSerializeField34() => _field34 != null; + + [SerializableField(35)] + private string _field35; + + [SerializableFieldSaveFlag(35)] + private bool ShouldSerializeField35() => _field35 != null; + + [SerializableField(36)] + private string _field36; + + [SerializableFieldSaveFlag(36)] + private bool ShouldSerializeField36() => _field36 != null; + + [SerializableField(37)] + private string _field37; + + [SerializableFieldSaveFlag(37)] + private bool ShouldSerializeField37() => _field37 != null; + + [SerializableField(38)] + private string _field38; + + [SerializableFieldSaveFlag(38)] + private bool ShouldSerializeField38() => _field38 != null; + + [SerializableField(39)] + private string _field39; + + [SerializableFieldSaveFlag(39)] + private bool ShouldSerializeField39() => _field39 != null; + + [SerializableField(40)] + private string _field40; + + [SerializableFieldSaveFlag(40)] + private bool ShouldSerializeField40() => _field40 != null; + + [SerializableField(41)] + private string _field41; + + [SerializableFieldSaveFlag(41)] + private bool ShouldSerializeField41() => _field41 != null; + + [SerializableField(42)] + private string _field42; + + [SerializableFieldSaveFlag(42)] + private bool ShouldSerializeField42() => _field42 != null; + + [SerializableField(43)] + private string _field43; + + [SerializableFieldSaveFlag(43)] + private bool ShouldSerializeField43() => _field43 != null; + + [SerializableField(44)] + private string _field44; + + [SerializableFieldSaveFlag(44)] + private bool ShouldSerializeField44() => _field44 != null; + + [SerializableField(45)] + private string _field45; + + [SerializableFieldSaveFlag(45)] + private bool ShouldSerializeField45() => _field45 != null; + + [SerializableField(46)] + private string _field46; + + [SerializableFieldSaveFlag(46)] + private bool ShouldSerializeField46() => _field46 != null; + + [SerializableField(47)] + private string _field47; + + [SerializableFieldSaveFlag(47)] + private bool ShouldSerializeField47() => _field47 != null; + + [SerializableField(48)] + private string _field48; + + [SerializableFieldSaveFlag(48)] + private bool ShouldSerializeField48() => _field48 != null; + + [SerializableField(49)] + private string _field49; + + [SerializableFieldSaveFlag(49)] + private bool ShouldSerializeField49() => _field49 != null; + + [SerializableField(50)] + private string _field50; + + [SerializableFieldSaveFlag(50)] + private bool ShouldSerializeField50() => _field50 != null; + + [SerializableField(51)] + private string _field51; + + [SerializableFieldSaveFlag(51)] + private bool ShouldSerializeField51() => _field51 != null; + + [SerializableField(52)] + private string _field52; + + [SerializableFieldSaveFlag(52)] + private bool ShouldSerializeField52() => _field52 != null; + + [SerializableField(53)] + private string _field53; + + [SerializableFieldSaveFlag(53)] + private bool ShouldSerializeField53() => _field53 != null; + + [SerializableField(54)] + private string _field54; + + [SerializableFieldSaveFlag(54)] + private bool ShouldSerializeField54() => _field54 != null; + + [SerializableField(55)] + private string _field55; + + [SerializableFieldSaveFlag(55)] + private bool ShouldSerializeField55() => _field55 != null; + + [SerializableField(56)] + private string _field56; + + [SerializableFieldSaveFlag(56)] + private bool ShouldSerializeField56() => _field56 != null; + + [SerializableField(57)] + private string _field57; + + [SerializableFieldSaveFlag(57)] + private bool ShouldSerializeField57() => _field57 != null; + + [SerializableField(58)] + private string _field58; + + [SerializableFieldSaveFlag(58)] + private bool ShouldSerializeField58() => _field58 != null; + + [SerializableField(59)] + private string _field59; + + [SerializableFieldSaveFlag(59)] + private bool ShouldSerializeField59() => _field59 != null; + + [SerializableField(60)] + private string _field60; + + [SerializableFieldSaveFlag(60)] + private bool ShouldSerializeField60() => _field60 != null; + + [SerializableField(61)] + private string _field61; + + [SerializableFieldSaveFlag(61)] + private bool ShouldSerializeField61() => _field61 != null; + + [SerializableField(62)] + private string _field62; + + [SerializableFieldSaveFlag(62)] + private bool ShouldSerializeField62() => _field62 != null; + + [SerializableField(63)] + private string _field63; + + [SerializableFieldSaveFlag(63)] + private bool ShouldSerializeField63() => _field63 != null; + + [SerializableField(64)] + private string _field64; + + [SerializableFieldSaveFlag(64)] + private bool ShouldSerializeField64() => _field64 != null; + + [SerializableField(65)] + private string _field65; + + [SerializableFieldSaveFlag(65)] + private bool ShouldSerializeField65() => _field65 != null; + + [SerializableField(66)] + private string _field66; + + [SerializableFieldSaveFlag(66)] + private bool ShouldSerializeField66() => _field66 != null; + + [SerializableField(67)] + private string _field67; + + [SerializableFieldSaveFlag(67)] + private bool ShouldSerializeField67() => _field67 != null; + + [SerializableField(68)] + private string _field68; + + [SerializableFieldSaveFlag(68)] + private bool ShouldSerializeField68() => _field68 != null; + + [SerializableField(69)] + private string _field69; + + [SerializableFieldSaveFlag(69)] + private bool ShouldSerializeField69() => _field69 != null; + + public DateTime Created { get; set; } + public Serial Serial { get; } + public bool Deleted => false; + public void Delete() { } + } +} diff --git a/ModernUO.Serialization.Generator.Tests/Snapshots/SaveFlagsUlong/Expected/Server.TestContent.UlongFlagsItem.Serialization.g.cs b/ModernUO.Serialization.Generator.Tests/Snapshots/SaveFlagsUlong/Expected/Server.TestContent.UlongFlagsItem.Serialization.g.cs new file mode 100644 index 0000000..0bd14b8 --- /dev/null +++ b/ModernUO.Serialization.Generator.Tests/Snapshots/SaveFlagsUlong/Expected/Server.TestContent.UlongFlagsItem.Serialization.g.cs @@ -0,0 +1,996 @@ +// +// This code was generated by the ModernUO Serialization Generator tool. +// Version: {VERSION} +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// + +#pragma warning disable + +namespace Server.TestContent +{ + [System.CodeDom.Compiler.GeneratedCode("ModernUO.Serialization.Generator", "{VERSION}")] + public partial class UlongFlagsItem + { + private const int SerializationVersion = 0; + + public string Field0 + { + get => _field0; + set + { + if (value != _field0) + { + _field0 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field1 + { + get => _field1; + set + { + if (value != _field1) + { + _field1 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field2 + { + get => _field2; + set + { + if (value != _field2) + { + _field2 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field3 + { + get => _field3; + set + { + if (value != _field3) + { + _field3 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field4 + { + get => _field4; + set + { + if (value != _field4) + { + _field4 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field5 + { + get => _field5; + set + { + if (value != _field5) + { + _field5 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field6 + { + get => _field6; + set + { + if (value != _field6) + { + _field6 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field7 + { + get => _field7; + set + { + if (value != _field7) + { + _field7 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field8 + { + get => _field8; + set + { + if (value != _field8) + { + _field8 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field9 + { + get => _field9; + set + { + if (value != _field9) + { + _field9 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field10 + { + get => _field10; + set + { + if (value != _field10) + { + _field10 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field11 + { + get => _field11; + set + { + if (value != _field11) + { + _field11 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field12 + { + get => _field12; + set + { + if (value != _field12) + { + _field12 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field13 + { + get => _field13; + set + { + if (value != _field13) + { + _field13 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field14 + { + get => _field14; + set + { + if (value != _field14) + { + _field14 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field15 + { + get => _field15; + set + { + if (value != _field15) + { + _field15 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field16 + { + get => _field16; + set + { + if (value != _field16) + { + _field16 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field17 + { + get => _field17; + set + { + if (value != _field17) + { + _field17 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field18 + { + get => _field18; + set + { + if (value != _field18) + { + _field18 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field19 + { + get => _field19; + set + { + if (value != _field19) + { + _field19 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field20 + { + get => _field20; + set + { + if (value != _field20) + { + _field20 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field21 + { + get => _field21; + set + { + if (value != _field21) + { + _field21 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field22 + { + get => _field22; + set + { + if (value != _field22) + { + _field22 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field23 + { + get => _field23; + set + { + if (value != _field23) + { + _field23 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field24 + { + get => _field24; + set + { + if (value != _field24) + { + _field24 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field25 + { + get => _field25; + set + { + if (value != _field25) + { + _field25 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field26 + { + get => _field26; + set + { + if (value != _field26) + { + _field26 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field27 + { + get => _field27; + set + { + if (value != _field27) + { + _field27 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field28 + { + get => _field28; + set + { + if (value != _field28) + { + _field28 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field29 + { + get => _field29; + set + { + if (value != _field29) + { + _field29 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field30 + { + get => _field30; + set + { + if (value != _field30) + { + _field30 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field31 + { + get => _field31; + set + { + if (value != _field31) + { + _field31 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field32 + { + get => _field32; + set + { + if (value != _field32) + { + _field32 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public string Field33 + { + get => _field33; + set + { + if (value != _field33) + { + _field33 = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public UlongFlagsItem(Server.Serial serial) + { + Serial = serial; + } + + public virtual void Serialize(Server.IGenericWriter writer) + { + writer.WriteEncodedInt(SerializationVersion); + + var saveFlags = SaveFlag.None; + if (ShouldSerializeField0()) + { + saveFlags |= SaveFlag.Field0; + } + if (ShouldSerializeField1()) + { + saveFlags |= SaveFlag.Field1; + } + if (ShouldSerializeField2()) + { + saveFlags |= SaveFlag.Field2; + } + if (ShouldSerializeField3()) + { + saveFlags |= SaveFlag.Field3; + } + if (ShouldSerializeField4()) + { + saveFlags |= SaveFlag.Field4; + } + if (ShouldSerializeField5()) + { + saveFlags |= SaveFlag.Field5; + } + if (ShouldSerializeField6()) + { + saveFlags |= SaveFlag.Field6; + } + if (ShouldSerializeField7()) + { + saveFlags |= SaveFlag.Field7; + } + if (ShouldSerializeField8()) + { + saveFlags |= SaveFlag.Field8; + } + if (ShouldSerializeField9()) + { + saveFlags |= SaveFlag.Field9; + } + if (ShouldSerializeField10()) + { + saveFlags |= SaveFlag.Field10; + } + if (ShouldSerializeField11()) + { + saveFlags |= SaveFlag.Field11; + } + if (ShouldSerializeField12()) + { + saveFlags |= SaveFlag.Field12; + } + if (ShouldSerializeField13()) + { + saveFlags |= SaveFlag.Field13; + } + if (ShouldSerializeField14()) + { + saveFlags |= SaveFlag.Field14; + } + if (ShouldSerializeField15()) + { + saveFlags |= SaveFlag.Field15; + } + if (ShouldSerializeField16()) + { + saveFlags |= SaveFlag.Field16; + } + if (ShouldSerializeField17()) + { + saveFlags |= SaveFlag.Field17; + } + if (ShouldSerializeField18()) + { + saveFlags |= SaveFlag.Field18; + } + if (ShouldSerializeField19()) + { + saveFlags |= SaveFlag.Field19; + } + if (ShouldSerializeField20()) + { + saveFlags |= SaveFlag.Field20; + } + if (ShouldSerializeField21()) + { + saveFlags |= SaveFlag.Field21; + } + if (ShouldSerializeField22()) + { + saveFlags |= SaveFlag.Field22; + } + if (ShouldSerializeField23()) + { + saveFlags |= SaveFlag.Field23; + } + if (ShouldSerializeField24()) + { + saveFlags |= SaveFlag.Field24; + } + if (ShouldSerializeField25()) + { + saveFlags |= SaveFlag.Field25; + } + if (ShouldSerializeField26()) + { + saveFlags |= SaveFlag.Field26; + } + if (ShouldSerializeField27()) + { + saveFlags |= SaveFlag.Field27; + } + if (ShouldSerializeField28()) + { + saveFlags |= SaveFlag.Field28; + } + if (ShouldSerializeField29()) + { + saveFlags |= SaveFlag.Field29; + } + if (ShouldSerializeField30()) + { + saveFlags |= SaveFlag.Field30; + } + if (ShouldSerializeField31()) + { + saveFlags |= SaveFlag.Field31; + } + if (ShouldSerializeField32()) + { + saveFlags |= SaveFlag.Field32; + } + if (ShouldSerializeField33()) + { + saveFlags |= SaveFlag.Field33; + } + writer.WriteEnum(saveFlags); + + if ((saveFlags & SaveFlag.Field0) != 0) + { + writer.Write(_field0); + } + + if ((saveFlags & SaveFlag.Field1) != 0) + { + writer.Write(_field1); + } + + if ((saveFlags & SaveFlag.Field2) != 0) + { + writer.Write(_field2); + } + + if ((saveFlags & SaveFlag.Field3) != 0) + { + writer.Write(_field3); + } + + if ((saveFlags & SaveFlag.Field4) != 0) + { + writer.Write(_field4); + } + + if ((saveFlags & SaveFlag.Field5) != 0) + { + writer.Write(_field5); + } + + if ((saveFlags & SaveFlag.Field6) != 0) + { + writer.Write(_field6); + } + + if ((saveFlags & SaveFlag.Field7) != 0) + { + writer.Write(_field7); + } + + if ((saveFlags & SaveFlag.Field8) != 0) + { + writer.Write(_field8); + } + + if ((saveFlags & SaveFlag.Field9) != 0) + { + writer.Write(_field9); + } + + if ((saveFlags & SaveFlag.Field10) != 0) + { + writer.Write(_field10); + } + + if ((saveFlags & SaveFlag.Field11) != 0) + { + writer.Write(_field11); + } + + if ((saveFlags & SaveFlag.Field12) != 0) + { + writer.Write(_field12); + } + + if ((saveFlags & SaveFlag.Field13) != 0) + { + writer.Write(_field13); + } + + if ((saveFlags & SaveFlag.Field14) != 0) + { + writer.Write(_field14); + } + + if ((saveFlags & SaveFlag.Field15) != 0) + { + writer.Write(_field15); + } + + if ((saveFlags & SaveFlag.Field16) != 0) + { + writer.Write(_field16); + } + + if ((saveFlags & SaveFlag.Field17) != 0) + { + writer.Write(_field17); + } + + if ((saveFlags & SaveFlag.Field18) != 0) + { + writer.Write(_field18); + } + + if ((saveFlags & SaveFlag.Field19) != 0) + { + writer.Write(_field19); + } + + if ((saveFlags & SaveFlag.Field20) != 0) + { + writer.Write(_field20); + } + + if ((saveFlags & SaveFlag.Field21) != 0) + { + writer.Write(_field21); + } + + if ((saveFlags & SaveFlag.Field22) != 0) + { + writer.Write(_field22); + } + + if ((saveFlags & SaveFlag.Field23) != 0) + { + writer.Write(_field23); + } + + if ((saveFlags & SaveFlag.Field24) != 0) + { + writer.Write(_field24); + } + + if ((saveFlags & SaveFlag.Field25) != 0) + { + writer.Write(_field25); + } + + if ((saveFlags & SaveFlag.Field26) != 0) + { + writer.Write(_field26); + } + + if ((saveFlags & SaveFlag.Field27) != 0) + { + writer.Write(_field27); + } + + if ((saveFlags & SaveFlag.Field28) != 0) + { + writer.Write(_field28); + } + + if ((saveFlags & SaveFlag.Field29) != 0) + { + writer.Write(_field29); + } + + if ((saveFlags & SaveFlag.Field30) != 0) + { + writer.Write(_field30); + } + + if ((saveFlags & SaveFlag.Field31) != 0) + { + writer.Write(_field31); + } + + if ((saveFlags & SaveFlag.Field32) != 0) + { + writer.Write(_field32); + } + + if ((saveFlags & SaveFlag.Field33) != 0) + { + writer.Write(_field33); + } + } + + public virtual void Deserialize(Server.IGenericReader reader) + { + var version = reader.ReadEncodedInt(); + + var saveFlags = reader.ReadEnum(); + + if ((saveFlags & SaveFlag.Field0) != 0) + { + _field0 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field1) != 0) + { + _field1 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field2) != 0) + { + _field2 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field3) != 0) + { + _field3 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field4) != 0) + { + _field4 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field5) != 0) + { + _field5 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field6) != 0) + { + _field6 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field7) != 0) + { + _field7 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field8) != 0) + { + _field8 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field9) != 0) + { + _field9 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field10) != 0) + { + _field10 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field11) != 0) + { + _field11 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field12) != 0) + { + _field12 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field13) != 0) + { + _field13 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field14) != 0) + { + _field14 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field15) != 0) + { + _field15 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field16) != 0) + { + _field16 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field17) != 0) + { + _field17 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field18) != 0) + { + _field18 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field19) != 0) + { + _field19 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field20) != 0) + { + _field20 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field21) != 0) + { + _field21 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field22) != 0) + { + _field22 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field23) != 0) + { + _field23 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field24) != 0) + { + _field24 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field25) != 0) + { + _field25 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field26) != 0) + { + _field26 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field27) != 0) + { + _field27 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field28) != 0) + { + _field28 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field29) != 0) + { + _field29 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field30) != 0) + { + _field30 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field31) != 0) + { + _field31 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field32) != 0) + { + _field32 = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Field33) != 0) + { + _field33 = reader.ReadString(); + } + } + + [System.Flags] + private enum SaveFlag : ulong + { + None = 0x0000000000000000, + Field0 = 0x0000000000000001, + Field1 = 0x0000000000000002, + Field2 = 0x0000000000000004, + Field3 = 0x0000000000000008, + Field4 = 0x0000000000000010, + Field5 = 0x0000000000000020, + Field6 = 0x0000000000000040, + Field7 = 0x0000000000000080, + Field8 = 0x0000000000000100, + Field9 = 0x0000000000000200, + Field10 = 0x0000000000000400, + Field11 = 0x0000000000000800, + Field12 = 0x0000000000001000, + Field13 = 0x0000000000002000, + Field14 = 0x0000000000004000, + Field15 = 0x0000000000008000, + Field16 = 0x0000000000010000, + Field17 = 0x0000000000020000, + Field18 = 0x0000000000040000, + Field19 = 0x0000000000080000, + Field20 = 0x0000000000100000, + Field21 = 0x0000000000200000, + Field22 = 0x0000000000400000, + Field23 = 0x0000000000800000, + Field24 = 0x0000000001000000, + Field25 = 0x0000000002000000, + Field26 = 0x0000000004000000, + Field27 = 0x0000000008000000, + Field28 = 0x0000000010000000, + Field29 = 0x0000000020000000, + Field30 = 0x0000000040000000, + Field31 = 0x0000000080000000, + Field32 = 0x0000000100000000, + Field33 = 0x0000000200000000, + } + } +} diff --git a/ModernUO.Serialization.Generator.Tests/Snapshots/SaveFlagsUlong/Input.cs b/ModernUO.Serialization.Generator.Tests/Snapshots/SaveFlagsUlong/Input.cs new file mode 100644 index 0000000..8b4a646 --- /dev/null +++ b/ModernUO.Serialization.Generator.Tests/Snapshots/SaveFlagsUlong/Input.cs @@ -0,0 +1,219 @@ +using System; +using ModernUO.Serialization; +using Server; + +namespace Server.TestContent +{ + [SerializationGenerator(0)] + public partial class UlongFlagsItem : ISerializable + { + [SerializableField(0)] + private string _field0; + + [SerializableFieldSaveFlag(0)] + private bool ShouldSerializeField0() => _field0 != null; + + [SerializableField(1)] + private string _field1; + + [SerializableFieldSaveFlag(1)] + private bool ShouldSerializeField1() => _field1 != null; + + [SerializableField(2)] + private string _field2; + + [SerializableFieldSaveFlag(2)] + private bool ShouldSerializeField2() => _field2 != null; + + [SerializableField(3)] + private string _field3; + + [SerializableFieldSaveFlag(3)] + private bool ShouldSerializeField3() => _field3 != null; + + [SerializableField(4)] + private string _field4; + + [SerializableFieldSaveFlag(4)] + private bool ShouldSerializeField4() => _field4 != null; + + [SerializableField(5)] + private string _field5; + + [SerializableFieldSaveFlag(5)] + private bool ShouldSerializeField5() => _field5 != null; + + [SerializableField(6)] + private string _field6; + + [SerializableFieldSaveFlag(6)] + private bool ShouldSerializeField6() => _field6 != null; + + [SerializableField(7)] + private string _field7; + + [SerializableFieldSaveFlag(7)] + private bool ShouldSerializeField7() => _field7 != null; + + [SerializableField(8)] + private string _field8; + + [SerializableFieldSaveFlag(8)] + private bool ShouldSerializeField8() => _field8 != null; + + [SerializableField(9)] + private string _field9; + + [SerializableFieldSaveFlag(9)] + private bool ShouldSerializeField9() => _field9 != null; + + [SerializableField(10)] + private string _field10; + + [SerializableFieldSaveFlag(10)] + private bool ShouldSerializeField10() => _field10 != null; + + [SerializableField(11)] + private string _field11; + + [SerializableFieldSaveFlag(11)] + private bool ShouldSerializeField11() => _field11 != null; + + [SerializableField(12)] + private string _field12; + + [SerializableFieldSaveFlag(12)] + private bool ShouldSerializeField12() => _field12 != null; + + [SerializableField(13)] + private string _field13; + + [SerializableFieldSaveFlag(13)] + private bool ShouldSerializeField13() => _field13 != null; + + [SerializableField(14)] + private string _field14; + + [SerializableFieldSaveFlag(14)] + private bool ShouldSerializeField14() => _field14 != null; + + [SerializableField(15)] + private string _field15; + + [SerializableFieldSaveFlag(15)] + private bool ShouldSerializeField15() => _field15 != null; + + [SerializableField(16)] + private string _field16; + + [SerializableFieldSaveFlag(16)] + private bool ShouldSerializeField16() => _field16 != null; + + [SerializableField(17)] + private string _field17; + + [SerializableFieldSaveFlag(17)] + private bool ShouldSerializeField17() => _field17 != null; + + [SerializableField(18)] + private string _field18; + + [SerializableFieldSaveFlag(18)] + private bool ShouldSerializeField18() => _field18 != null; + + [SerializableField(19)] + private string _field19; + + [SerializableFieldSaveFlag(19)] + private bool ShouldSerializeField19() => _field19 != null; + + [SerializableField(20)] + private string _field20; + + [SerializableFieldSaveFlag(20)] + private bool ShouldSerializeField20() => _field20 != null; + + [SerializableField(21)] + private string _field21; + + [SerializableFieldSaveFlag(21)] + private bool ShouldSerializeField21() => _field21 != null; + + [SerializableField(22)] + private string _field22; + + [SerializableFieldSaveFlag(22)] + private bool ShouldSerializeField22() => _field22 != null; + + [SerializableField(23)] + private string _field23; + + [SerializableFieldSaveFlag(23)] + private bool ShouldSerializeField23() => _field23 != null; + + [SerializableField(24)] + private string _field24; + + [SerializableFieldSaveFlag(24)] + private bool ShouldSerializeField24() => _field24 != null; + + [SerializableField(25)] + private string _field25; + + [SerializableFieldSaveFlag(25)] + private bool ShouldSerializeField25() => _field25 != null; + + [SerializableField(26)] + private string _field26; + + [SerializableFieldSaveFlag(26)] + private bool ShouldSerializeField26() => _field26 != null; + + [SerializableField(27)] + private string _field27; + + [SerializableFieldSaveFlag(27)] + private bool ShouldSerializeField27() => _field27 != null; + + [SerializableField(28)] + private string _field28; + + [SerializableFieldSaveFlag(28)] + private bool ShouldSerializeField28() => _field28 != null; + + [SerializableField(29)] + private string _field29; + + [SerializableFieldSaveFlag(29)] + private bool ShouldSerializeField29() => _field29 != null; + + [SerializableField(30)] + private string _field30; + + [SerializableFieldSaveFlag(30)] + private bool ShouldSerializeField30() => _field30 != null; + + [SerializableField(31)] + private string _field31; + + [SerializableFieldSaveFlag(31)] + private bool ShouldSerializeField31() => _field31 != null; + + [SerializableField(32)] + private string _field32; + + [SerializableFieldSaveFlag(32)] + private bool ShouldSerializeField32() => _field32 != null; + + [SerializableField(33)] + private string _field33; + + [SerializableFieldSaveFlag(33)] + private bool ShouldSerializeField33() => _field33 != null; + + public DateTime Created { get; set; } + public Serial Serial { get; } + public bool Deleted => false; + public void Delete() { } + } +} diff --git a/ModernUO.Serialization.Generator.Tests/Snapshots/SaveFlagsWithDefaults/Expected/Server.TestContent.SaveFlagsItem.Serialization.g.cs b/ModernUO.Serialization.Generator.Tests/Snapshots/SaveFlagsWithDefaults/Expected/Server.TestContent.SaveFlagsItem.Serialization.g.cs new file mode 100644 index 0000000..2da73d0 --- /dev/null +++ b/ModernUO.Serialization.Generator.Tests/Snapshots/SaveFlagsWithDefaults/Expected/Server.TestContent.SaveFlagsItem.Serialization.g.cs @@ -0,0 +1,153 @@ +// +// This code was generated by the ModernUO Serialization Generator tool. +// Version: {VERSION} +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// + +#pragma warning disable + +namespace Server.TestContent +{ + [System.CodeDom.Compiler.GeneratedCode("ModernUO.Serialization.Generator", "{VERSION}")] + public partial class SaveFlagsItem + { + private const int SerializationVersion = 0; + + public string Name + { + get => _name; + set + { + if (value != _name) + { + _name = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public int Charges + { + get => _charges; + set + { + if (value != _charges) + { + _charges = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public System.DateTime Expires + { + get => _expires; + set + { + if (value != _expires) + { + _expires = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public bool Identified + { + get => _identified; + set + { + if (value != _identified) + { + _identified = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public SaveFlagsItem(Server.Serial serial) + { + Serial = serial; + } + + public virtual void Serialize(Server.IGenericWriter writer) + { + writer.WriteEncodedInt(SerializationVersion); + + var saveFlags = SaveFlag.None; + if (ShouldSerializeName()) + { + saveFlags |= SaveFlag.Name; + } + if (ShouldSerializeCharges()) + { + saveFlags |= SaveFlag.Charges; + } + if (ShouldSerializeExpires()) + { + saveFlags |= SaveFlag.Expires; + } + writer.WriteEnum(saveFlags); + + if ((saveFlags & SaveFlag.Name) != 0) + { + writer.Write(_name); + } + + if ((saveFlags & SaveFlag.Charges) != 0) + { + writer.Write(_charges); + } + + if ((saveFlags & SaveFlag.Expires) != 0) + { + writer.Write(_expires); + } + + writer.Write(_identified); + } + + public virtual void Deserialize(Server.IGenericReader reader) + { + var version = reader.ReadEncodedInt(); + + var saveFlags = reader.ReadEnum(); + + if ((saveFlags & SaveFlag.Name) != 0) + { + _name = reader.ReadString(); + } + + if ((saveFlags & SaveFlag.Charges) != 0) + { + _charges = reader.ReadInt(); + } + else + { + _charges = ChargesDefaultValue(); + } + + if ((saveFlags & SaveFlag.Expires) != 0) + { + _expires = reader.ReadDateTime(); + } + else + { + _expires = ExpiresDefaultValue(); + } + + _identified = reader.ReadBool(); + } + + [System.Flags] + private enum SaveFlag + { + None = 0x00000000, + Name = 0x00000001, + Charges = 0x00000002, + Expires = 0x00000004, + } + } +} diff --git a/ModernUO.Serialization.Generator.Tests/Snapshots/SaveFlagsWithDefaults/Input.cs b/ModernUO.Serialization.Generator.Tests/Snapshots/SaveFlagsWithDefaults/Input.cs new file mode 100644 index 0000000..fd5ec70 --- /dev/null +++ b/ModernUO.Serialization.Generator.Tests/Snapshots/SaveFlagsWithDefaults/Input.cs @@ -0,0 +1,42 @@ +using System; +using ModernUO.Serialization; +using Server; + +namespace Server.TestContent +{ + [SerializationGenerator(0)] + public partial class SaveFlagsItem : ISerializable + { + [SerializableField(0)] + private string _name; + + [SerializableFieldSaveFlag(0)] + private bool ShouldSerializeName() => _name != null; + + [SerializableField(1)] + private int _charges; + + [SerializableFieldSaveFlag(1)] + private bool ShouldSerializeCharges() => _charges != 8; + + [SerializableFieldDefault(1)] + private int ChargesDefaultValue() => 8; + + [SerializableField(2)] + private DateTime _expires; + + [SerializableFieldSaveFlag(2)] + private bool ShouldSerializeExpires() => _expires != DateTime.MinValue; + + [SerializableFieldDefault(2)] + private DateTime ExpiresDefaultValue() => DateTime.MinValue; + + [SerializableField(3)] + private bool _identified; + + public DateTime Created { get; set; } + public Serial Serial { get; } + public bool Deleted => false; + public void Delete() { } + } +} diff --git a/ModernUO.Serialization.Generator.Tests/Snapshots/SortedSetWithComparer/Expected/Server.TestContent.SortedSetItem.Serialization.g.cs b/ModernUO.Serialization.Generator.Tests/Snapshots/SortedSetWithComparer/Expected/Server.TestContent.SortedSetItem.Serialization.g.cs new file mode 100644 index 0000000..329f904 --- /dev/null +++ b/ModernUO.Serialization.Generator.Tests/Snapshots/SortedSetWithComparer/Expected/Server.TestContent.SortedSetItem.Serialization.g.cs @@ -0,0 +1,87 @@ +// +// This code was generated by the ModernUO Serialization Generator tool. +// Version: {VERSION} +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// + +#pragma warning disable + +namespace Server.TestContent +{ + [System.CodeDom.Compiler.GeneratedCode("ModernUO.Serialization.Generator", "{VERSION}")] + public partial class SortedSetItem + { + private const int SerializationVersion = 0; + + public System.Collections.Generic.SortedSet Names + { + get => _names; + set + { + if (value != _names) + { + _names = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public void AddToNames(string value) + { + Names.Add(value); + Server.ISerializableExtensions.MarkDirty(this); + } + + public void RemoveFromNames(string value) + { + Names.Remove(value); + Server.ISerializableExtensions.MarkDirty(this); + } + + + public void ClearNames() + { + Names.Clear(); + Server.ISerializableExtensions.MarkDirty(this); + } + + public SortedSetItem(Server.Serial serial) + { + Serial = serial; + } + + public virtual void Serialize(Server.IGenericWriter writer) + { + writer.WriteEncodedInt(SerializationVersion); + + var _namesCount = _names?.Count ?? 0; + writer.WriteEncodedInt(_namesCount); + if (_namesCount > 0) + { + foreach (var _namesEntry in _names!) + { + writer.Write(_namesEntry); + } + } + } + + public virtual void Deserialize(Server.IGenericReader reader) + { + var version = reader.ReadEncodedInt(); + + string _namesEntry; + var _namesCount = reader.ReadEncodedInt(); + _names = new System.Collections.Generic.SortedSet(new Server.TestContent.CaseInsensitiveComparer()); + for (var _namesIndex = 0; _namesIndex < _namesCount; _namesIndex++) + { + _namesEntry = reader.ReadString(); + if (typeof(string).IsValueType || _namesEntry != default) + { + _names.Add(_namesEntry); + } + } + } + } +} diff --git a/ModernUO.Serialization.Generator.Tests/Snapshots/SortedSetWithComparer/Input.cs b/ModernUO.Serialization.Generator.Tests/Snapshots/SortedSetWithComparer/Input.cs new file mode 100644 index 0000000..6b722a1 --- /dev/null +++ b/ModernUO.Serialization.Generator.Tests/Snapshots/SortedSetWithComparer/Input.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using ModernUO.Serialization; +using Server; + +namespace Server.TestContent +{ + public class CaseInsensitiveComparer : IComparer + { + public int Compare(string x, string y) => string.Compare(x, y, StringComparison.OrdinalIgnoreCase); + } + + [SerializationGenerator(0)] + public partial class SortedSetItem : ISerializable + { + [SerializableField(0)] + [SortedSetComparer(typeof(CaseInsensitiveComparer))] + private SortedSet _names; + + public DateTime Created { get; set; } + public Serial Serial { get; } + public bool Deleted => false; + public void Delete() { } + } +} diff --git a/ModernUO.Serialization.Generator.Tests/Snapshots/Structs/Expected/Server.TestContent.FactoryStruct.Serialization.g.cs b/ModernUO.Serialization.Generator.Tests/Snapshots/Structs/Expected/Server.TestContent.FactoryStruct.Serialization.g.cs new file mode 100644 index 0000000..7b5306c --- /dev/null +++ b/ModernUO.Serialization.Generator.Tests/Snapshots/Structs/Expected/Server.TestContent.FactoryStruct.Serialization.g.cs @@ -0,0 +1,44 @@ +// +// This code was generated by the ModernUO Serialization Generator tool. +// Version: {VERSION} +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// + +#pragma warning disable + +namespace Server.TestContent +{ + [System.CodeDom.Compiler.GeneratedCode("ModernUO.Serialization.Generator", "{VERSION}")] + public partial struct FactoryStruct + { + private const int SerializationVersion = 0; + + public int Value + { + get => _value; + set + { + if (value != _value) + { + _value = value; + } + } + } + + public virtual void Serialize(Server.IGenericWriter writer) + { + writer.WriteEncodedInt(SerializationVersion); + + writer.Write(_value); + } + + public virtual void Deserialize(Server.IGenericReader reader) + { + var version = reader.ReadEncodedInt(); + + _value = reader.ReadInt(); + } + } +} diff --git a/ModernUO.Serialization.Generator.Tests/Snapshots/Structs/Expected/Server.TestContent.InstanceStruct.Serialization.g.cs b/ModernUO.Serialization.Generator.Tests/Snapshots/Structs/Expected/Server.TestContent.InstanceStruct.Serialization.g.cs new file mode 100644 index 0000000..e177af1 --- /dev/null +++ b/ModernUO.Serialization.Generator.Tests/Snapshots/Structs/Expected/Server.TestContent.InstanceStruct.Serialization.g.cs @@ -0,0 +1,44 @@ +// +// This code was generated by the ModernUO Serialization Generator tool. +// Version: {VERSION} +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// + +#pragma warning disable + +namespace Server.TestContent +{ + [System.CodeDom.Compiler.GeneratedCode("ModernUO.Serialization.Generator", "{VERSION}")] + public partial struct InstanceStruct + { + private const int SerializationVersion = 0; + + public int Value + { + get => _value; + set + { + if (value != _value) + { + _value = value; + } + } + } + + public virtual void Serialize(Server.IGenericWriter writer) + { + writer.WriteEncodedInt(SerializationVersion); + + writer.Write(_value); + } + + public virtual void Deserialize(Server.IGenericReader reader) + { + var version = reader.ReadEncodedInt(); + + _value = reader.ReadInt(); + } + } +} diff --git a/ModernUO.Serialization.Generator.Tests/Snapshots/Structs/Input.cs b/ModernUO.Serialization.Generator.Tests/Snapshots/Structs/Input.cs new file mode 100644 index 0000000..829f128 --- /dev/null +++ b/ModernUO.Serialization.Generator.Tests/Snapshots/Structs/Input.cs @@ -0,0 +1,28 @@ +using ModernUO.Serialization; +using Server; + +namespace Server.TestContent +{ + [SerializationGenerator(0)] + public partial struct FactoryStruct + { + [SerializableField(0)] + private int _value; + + public static FactoryStruct Deserialize(IGenericReader reader) + { + return new FactoryStruct(); + } + } + + [SerializationGenerator(0)] + public partial struct InstanceStruct + { + [SerializableField(0)] + private int _value; + + public void Deserialize(IGenericReader reader) + { + } + } +} diff --git a/ModernUO.Serialization.Generator.Tests/Snapshots/Structs/KnownBroken.txt b/ModernUO.Serialization.Generator.Tests/Snapshots/Structs/KnownBroken.txt new file mode 100644 index 0000000..9b75a96 --- /dev/null +++ b/ModernUO.Serialization.Generator.Tests/Snapshots/Structs/KnownBroken.txt @@ -0,0 +1,3 @@ +Struct emission marks Serialize/Deserialize as `virtual`, which is illegal on structs +(CS0106). The pinned output preserves the current behavior; fixing the emission should +update this snapshot and delete this marker. diff --git a/ModernUO.Serialization.Generator.Tests/Snapshots/TimerAndDirtyTracking/Expected/Server.TestContent.OwnerEntity.Serialization.g.cs b/ModernUO.Serialization.Generator.Tests/Snapshots/TimerAndDirtyTracking/Expected/Server.TestContent.OwnerEntity.Serialization.g.cs new file mode 100644 index 0000000..4a45691 --- /dev/null +++ b/ModernUO.Serialization.Generator.Tests/Snapshots/TimerAndDirtyTracking/Expected/Server.TestContent.OwnerEntity.Serialization.g.cs @@ -0,0 +1,50 @@ +// +// This code was generated by the ModernUO Serialization Generator tool. +// Version: {VERSION} +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// + +#pragma warning disable + +namespace Server.TestContent +{ + [System.CodeDom.Compiler.GeneratedCode("ModernUO.Serialization.Generator", "{VERSION}")] + public partial class OwnerEntity + { + private const int SerializationVersion = 0; + + public string Name + { + get => _name; + set + { + if (value != _name) + { + _name = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public OwnerEntity(Server.Serial serial) + { + Serial = serial; + } + + public virtual void Serialize(Server.IGenericWriter writer) + { + writer.WriteEncodedInt(SerializationVersion); + + writer.Write(_name); + } + + public virtual void Deserialize(Server.IGenericReader reader) + { + var version = reader.ReadEncodedInt(); + + _name = reader.ReadString(); + } + } +} diff --git a/ModernUO.Serialization.Generator.Tests/Snapshots/TimerAndDirtyTracking/Expected/Server.TestContent.TrackedChild.Serialization.g.cs b/ModernUO.Serialization.Generator.Tests/Snapshots/TimerAndDirtyTracking/Expected/Server.TestContent.TrackedChild.Serialization.g.cs new file mode 100644 index 0000000..340705e --- /dev/null +++ b/ModernUO.Serialization.Generator.Tests/Snapshots/TimerAndDirtyTracking/Expected/Server.TestContent.TrackedChild.Serialization.g.cs @@ -0,0 +1,69 @@ +// +// This code was generated by the ModernUO Serialization Generator tool. +// Version: {VERSION} +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// + +#pragma warning disable + +namespace Server.TestContent +{ + [System.CodeDom.Compiler.GeneratedCode("ModernUO.Serialization.Generator", "{VERSION}")] + public partial class TrackedChild + { + private const int SerializationVersion = 0; + + public virtual void MarkDirty() + { + Server.ISerializableExtensions.MarkDirty(_owner); + } + + public Server.Timer RefreshTimer + { + get => _refreshTimer; + set + { + if (value != _refreshTimer) + { + _refreshTimer = value; + MarkDirty(); + } + } + } + + public int Progress + { + get => _progress; + set + { + if (value != _progress) + { + _progress = value; + MarkDirty(); + } + } + } + + public virtual void Serialize(Server.IGenericWriter writer) + { + writer.Write(SerializationVersion); + + writer.Write(RefreshTimer?.Next ?? System.DateTime.MinValue); + + writer.Write(_progress); + } + + public virtual void Deserialize(Server.IGenericReader reader) + { + var version = reader.ReadInt(); + + var RefreshTimerNext = reader.ReadDateTime(); + var RefreshTimerDelay = RefreshTimerNext == System.DateTime.MinValue ? System.TimeSpan.MinValue : RefreshTimerNext - Core.Now; + DeserializeRefreshTimer(RefreshTimerDelay); + + _progress = reader.ReadInt(); + } + } +} diff --git a/ModernUO.Serialization.Generator.Tests/Snapshots/TimerAndDirtyTracking/Input.cs b/ModernUO.Serialization.Generator.Tests/Snapshots/TimerAndDirtyTracking/Input.cs new file mode 100644 index 0000000..9898474 --- /dev/null +++ b/ModernUO.Serialization.Generator.Tests/Snapshots/TimerAndDirtyTracking/Input.cs @@ -0,0 +1,37 @@ +using System; +using ModernUO.Serialization; +using Server; + +namespace Server.TestContent +{ + [SerializationGenerator(0)] + public partial class OwnerEntity : ISerializable + { + [SerializableField(0)] + private string _name; + + public DateTime Created { get; set; } + public Serial Serial { get; } + public bool Deleted => false; + public void Delete() { } + } + + [SerializationGenerator(0, false)] + public partial class TrackedChild + { + [DirtyTrackingEntity] + private OwnerEntity _owner; + + [SerializableField(0)] + private Timer _refreshTimer; + + [DeserializeTimerField(0)] + private void DeserializeRefreshTimer(TimeSpan delay) + { + _refreshTimer = new Timer(); + } + + [SerializableField(1)] + private int _progress; + } +} diff --git a/ModernUO.Serialization.Generator.Tests/Snapshots/UOTypes/Expected/Server.TestContent.UOTypesItem.Serialization.g.cs b/ModernUO.Serialization.Generator.Tests/Snapshots/UOTypes/Expected/Server.TestContent.UOTypesItem.Serialization.g.cs new file mode 100644 index 0000000..e085978 --- /dev/null +++ b/ModernUO.Serialization.Generator.Tests/Snapshots/UOTypes/Expected/Server.TestContent.UOTypesItem.Serialization.g.cs @@ -0,0 +1,118 @@ +// +// This code was generated by the ModernUO Serialization Generator tool. +// Version: {VERSION} +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// + +#pragma warning disable + +namespace Server.TestContent +{ + [System.CodeDom.Compiler.GeneratedCode("ModernUO.Serialization.Generator", "{VERSION}")] + public partial class UOTypesItem + { + private const int SerializationVersion = 0; + + public Server.Serial LinkedSerial + { + get => _linkedSerial; + set + { + if (value != _linkedSerial) + { + _linkedSerial = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public Server.Point2D Location2D + { + get => _location2D; + set + { + if (value != _location2D) + { + _location2D = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public Server.Point3D Location3D + { + get => _location3D; + set + { + if (value != _location3D) + { + _location3D = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public Server.Rectangle2D Bounds2D + { + get => _bounds2D; + set + { + if (value != _bounds2D) + { + _bounds2D = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public Server.Rectangle3D Bounds3D + { + get => _bounds3D; + set + { + if (value != _bounds3D) + { + _bounds3D = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public UOTypesItem(Server.Serial serial) + { + Serial = serial; + } + + public virtual void Serialize(Server.IGenericWriter writer) + { + writer.WriteEncodedInt(SerializationVersion); + + writer.Write(_linkedSerial); + + writer.Write(_location2D); + + writer.Write(_location3D); + + writer.Write(_bounds2D); + + writer.Write(_bounds3D); + } + + public virtual void Deserialize(Server.IGenericReader reader) + { + var version = reader.ReadEncodedInt(); + + _linkedSerial = reader.ReadSerial(); + + _location2D = reader.ReadPoint2D(); + + _location3D = reader.ReadPoint3D(); + + _bounds2D = reader.ReadRect2D(); + + _bounds3D = reader.ReadRect3D(); + } + } +} diff --git a/ModernUO.Serialization.Generator.Tests/Snapshots/UOTypes/Input.cs b/ModernUO.Serialization.Generator.Tests/Snapshots/UOTypes/Input.cs new file mode 100644 index 0000000..4895722 --- /dev/null +++ b/ModernUO.Serialization.Generator.Tests/Snapshots/UOTypes/Input.cs @@ -0,0 +1,30 @@ +using System; +using ModernUO.Serialization; +using Server; + +namespace Server.TestContent +{ + [SerializationGenerator(0)] + public partial class UOTypesItem : ISerializable + { + [SerializableField(0)] + private Serial _linkedSerial; + + [SerializableField(1)] + private Point2D _location2D; + + [SerializableField(2)] + private Point3D _location3D; + + [SerializableField(3)] + private Rectangle2D _bounds2D; + + [SerializableField(4)] + private Rectangle3D _bounds3D; + + public DateTime Created { get; set; } + public Serial Serial { get; } + public bool Deleted => false; + public void Delete() { } + } +} diff --git a/ModernUO.Serialization.Generator.Tests/Snapshots/VersionedMigrations/Expected/Server.TestContent.MigratingItem.Serialization.g.cs b/ModernUO.Serialization.Generator.Tests/Snapshots/VersionedMigrations/Expected/Server.TestContent.MigratingItem.Serialization.g.cs new file mode 100644 index 0000000..29ce696 --- /dev/null +++ b/ModernUO.Serialization.Generator.Tests/Snapshots/VersionedMigrations/Expected/Server.TestContent.MigratingItem.Serialization.g.cs @@ -0,0 +1,118 @@ +// +// This code was generated by the ModernUO Serialization Generator tool. +// Version: {VERSION} +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// + +#pragma warning disable + +namespace Server.TestContent +{ + [System.CodeDom.Compiler.GeneratedCode("ModernUO.Serialization.Generator", "{VERSION}")] + public partial class MigratingItem + { + private const int SerializationVersion = 2; + + public string Name + { + get => _name; + set + { + if (value != _name) + { + _name = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public int Charges + { + get => _charges; + set + { + if (value != _charges) + { + _charges = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public bool Identified + { + get => _identified; + set + { + if (value != _identified) + { + _identified = value; + Server.ISerializableExtensions.MarkDirty(this); + } + } + } + + public MigratingItem(Server.Serial serial) + { + Serial = serial; + } + + ref struct V0Content + { + internal readonly string Name; + internal V0Content(IGenericReader reader, Server.TestContent.MigratingItem entity) + { + Name = reader.ReadString(); + } + } + + ref struct V1Content + { + internal readonly string Name; + internal readonly int Charges; + internal V1Content(IGenericReader reader, Server.TestContent.MigratingItem entity) + { + Name = reader.ReadString(); + Charges = reader.ReadInt(); + } + } + + public virtual void Serialize(Server.IGenericWriter writer) + { + writer.WriteEncodedInt(SerializationVersion); + + writer.Write(_name); + + writer.Write(_charges); + + writer.Write(_identified); + } + + public virtual void Deserialize(Server.IGenericReader reader) + { + var version = reader.ReadEncodedInt(); + + if (version == 0) + { + MigrateFrom(new V0Content(reader, this)); + Server.ISerializableExtensions.MarkDirty(this); + return; + } + + if (version == 1) + { + MigrateFrom(new V1Content(reader, this)); + Server.ISerializableExtensions.MarkDirty(this); + return; + } + + _name = reader.ReadString(); + + _charges = reader.ReadInt(); + + _identified = reader.ReadBool(); + } + } +} diff --git a/ModernUO.Serialization.Generator.Tests/Snapshots/VersionedMigrations/Input.cs b/ModernUO.Serialization.Generator.Tests/Snapshots/VersionedMigrations/Input.cs new file mode 100644 index 0000000..d796b34 --- /dev/null +++ b/ModernUO.Serialization.Generator.Tests/Snapshots/VersionedMigrations/Input.cs @@ -0,0 +1,38 @@ +using System; +using ModernUO.Serialization; +using Server; + +namespace Server.TestContent +{ + [SerializationGenerator(2)] + public partial class MigratingItem : ISerializable + { + [SerializableField(0)] + private string _name; + + [SerializableField(1)] + private int _charges; + + [SerializableField(2)] + private bool _identified; + + public DateTime Created { get; set; } + public Serial Serial { get; } + public bool Deleted => false; + public void Delete() { } + + private void MigrateFrom(V0Content content) + { + _name = content.Name; + _charges = 0; + _identified = false; + } + + private void MigrateFrom(V1Content content) + { + _name = content.Name; + _charges = content.Charges; + _identified = false; + } + } +} diff --git a/ModernUO.Serialization.Generator.Tests/Snapshots/VersionedMigrations/Server.TestContent.MigratingItem.v0.json b/ModernUO.Serialization.Generator.Tests/Snapshots/VersionedMigrations/Server.TestContent.MigratingItem.v0.json new file mode 100644 index 0000000..a853b2b --- /dev/null +++ b/ModernUO.Serialization.Generator.Tests/Snapshots/VersionedMigrations/Server.TestContent.MigratingItem.v0.json @@ -0,0 +1,11 @@ +{ + "version": 0, + "type": "Server.TestContent.MigratingItem", + "properties": [ + { + "name": "Name", + "type": "string", + "rule": "PrimitiveTypeMigrationRule" + } + ] +} diff --git a/ModernUO.Serialization.Generator.Tests/Snapshots/VersionedMigrations/Server.TestContent.MigratingItem.v1.json b/ModernUO.Serialization.Generator.Tests/Snapshots/VersionedMigrations/Server.TestContent.MigratingItem.v1.json new file mode 100644 index 0000000..78da5e7 --- /dev/null +++ b/ModernUO.Serialization.Generator.Tests/Snapshots/VersionedMigrations/Server.TestContent.MigratingItem.v1.json @@ -0,0 +1,16 @@ +{ + "version": 1, + "type": "Server.TestContent.MigratingItem", + "properties": [ + { + "name": "Name", + "type": "string", + "rule": "PrimitiveTypeMigrationRule" + }, + { + "name": "Charges", + "type": "int", + "rule": "PrimitiveTypeMigrationRule" + } + ] +} diff --git a/ModernUO.Serialization.SchemaGenerator/SourceCodeAnalysis.cs b/ModernUO.Serialization.SchemaGenerator/SourceCodeAnalysis.cs index 286d4d5..e4fc8ca 100644 --- a/ModernUO.Serialization.SchemaGenerator/SourceCodeAnalysis.cs +++ b/ModernUO.Serialization.SchemaGenerator/SourceCodeAnalysis.cs @@ -28,7 +28,9 @@ public static class SourceCodeAnalysis { public static async Task> GetProjectsAsync(string solutionPath) { - if (!File.Exists(solutionPath) || !solutionPath.EndsWith(".sln", StringComparison.Ordinal)) + if (!File.Exists(solutionPath) || + !solutionPath.EndsWith(".sln", StringComparison.Ordinal) && + !solutionPath.EndsWith(".slnx", StringComparison.Ordinal)) { throw new FileNotFoundException($"Could not open a valid solution at location {solutionPath}"); } diff --git a/SerializationGenerator.sln b/SerializationGenerator.sln index c7da238..3c65300 100644 --- a/SerializationGenerator.sln +++ b/SerializationGenerator.sln @@ -8,6 +8,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ModernUO.Serialization.Anno EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ModernUO.Serialization.Generator.Tests", "ModernUO.Serialization.Generator.Tests\ModernUO.Serialization.Generator.Tests.csproj", "{E670BC05-D4A9-4959-B645-A44CEA4A4038}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ModernUO.Serialization.Generator.DiffTool", "ModernUO.Serialization.Generator.DiffTool\ModernUO.Serialization.Generator.DiffTool.csproj", "{FF6B6037-035A-4F15-8785-65AE88CBC0E0}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ModernUO.Serialization.Generator.Benchmarks", "ModernUO.Serialization.Generator.Benchmarks\ModernUO.Serialization.Generator.Benchmarks.csproj", "{8F2FC821-1CB4-4933-8080-8B07FF9E1472}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -66,6 +70,30 @@ Global {E670BC05-D4A9-4959-B645-A44CEA4A4038}.Release|x64.Build.0 = Release|Any CPU {E670BC05-D4A9-4959-B645-A44CEA4A4038}.Release|x86.ActiveCfg = Release|Any CPU {E670BC05-D4A9-4959-B645-A44CEA4A4038}.Release|x86.Build.0 = Release|Any CPU + {FF6B6037-035A-4F15-8785-65AE88CBC0E0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FF6B6037-035A-4F15-8785-65AE88CBC0E0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FF6B6037-035A-4F15-8785-65AE88CBC0E0}.Debug|x64.ActiveCfg = Debug|Any CPU + {FF6B6037-035A-4F15-8785-65AE88CBC0E0}.Debug|x64.Build.0 = Debug|Any CPU + {FF6B6037-035A-4F15-8785-65AE88CBC0E0}.Debug|x86.ActiveCfg = Debug|Any CPU + {FF6B6037-035A-4F15-8785-65AE88CBC0E0}.Debug|x86.Build.0 = Debug|Any CPU + {FF6B6037-035A-4F15-8785-65AE88CBC0E0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FF6B6037-035A-4F15-8785-65AE88CBC0E0}.Release|Any CPU.Build.0 = Release|Any CPU + {FF6B6037-035A-4F15-8785-65AE88CBC0E0}.Release|x64.ActiveCfg = Release|Any CPU + {FF6B6037-035A-4F15-8785-65AE88CBC0E0}.Release|x64.Build.0 = Release|Any CPU + {FF6B6037-035A-4F15-8785-65AE88CBC0E0}.Release|x86.ActiveCfg = Release|Any CPU + {FF6B6037-035A-4F15-8785-65AE88CBC0E0}.Release|x86.Build.0 = Release|Any CPU + {8F2FC821-1CB4-4933-8080-8B07FF9E1472}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8F2FC821-1CB4-4933-8080-8B07FF9E1472}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8F2FC821-1CB4-4933-8080-8B07FF9E1472}.Debug|x64.ActiveCfg = Debug|Any CPU + {8F2FC821-1CB4-4933-8080-8B07FF9E1472}.Debug|x64.Build.0 = Debug|Any CPU + {8F2FC821-1CB4-4933-8080-8B07FF9E1472}.Debug|x86.ActiveCfg = Debug|Any CPU + {8F2FC821-1CB4-4933-8080-8B07FF9E1472}.Debug|x86.Build.0 = Debug|Any CPU + {8F2FC821-1CB4-4933-8080-8B07FF9E1472}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8F2FC821-1CB4-4933-8080-8B07FF9E1472}.Release|Any CPU.Build.0 = Release|Any CPU + {8F2FC821-1CB4-4933-8080-8B07FF9E1472}.Release|x64.ActiveCfg = Release|Any CPU + {8F2FC821-1CB4-4933-8080-8B07FF9E1472}.Release|x64.Build.0 = Release|Any CPU + {8F2FC821-1CB4-4933-8080-8B07FF9E1472}.Release|x86.ActiveCfg = Release|Any CPU + {8F2FC821-1CB4-4933-8080-8B07FF9E1472}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE