ModernUO/azure-pipelines.yml
Kamron Batman 9afa4e4cab
feat: Source generated Serialization/Deserialization (#550)
### Features
* Fully abstracts serialization by using compile-time attributes.
* Supports serializing the following:
  - Primitives (integers, strings, etc)
  - IP Addresses
  - BigDecimal
  - DateTime, Delta DateTimes
  - TimeSpan
  - Server.Race
  - Server.Map
  - Point2D, Point3D, Rect2D, Rect3D
  - Existing/New `ISerializable` references
  - Lists/Sets of serializable types
  - Type with a `Serialize` method and constructor that takes an `IGenericReader`
* Supports forward-only migration
* Supports existing RunUO deserialization for older versions by changing to the following signature:
  - `public void OldDeserialize(IGenericReader reader, int version)`
  - Must remove deserializing the version since this is already done
* Supports serializing from private fields or custom made properties.
* Types do not require inheriting Item/Mobile. Code gen will fully create `ISerializable` information.
  - This is not recommended yet, since it requires wiring to `Persistence` which will cause lots of unresolved symbol errors until code gen is built.

### Example
```cs
using System.Collections.Generic;

namespace Server.Items
{
    [Serializable(1)]
    public partial class TestItem1 : Item
    {
        [SerializableField(1)]
        [SerializableFieldAttr("[CommandProperty(AccessLevel.Administrator)]")]
        private List<Item> _someProperty;

        private void Deserialize(IGenericReader reader, int version)
        {
        }
    }
}
```

Generates this:
```cs
namespace Server.Items
{
    public partial class TestItem1
    {
#pragma warning disable 0414
        private const int _version = 1;
#pragma warning restore 0414

        [CommandProperty(AccessLevel.Administrator)]
        public System.Collections.Generic.List<Server.Item> SomeProperty
        {
            get => _someProperty;
            set
            {
                if (value != _someProperty)
                {
                    ((ISerializable)this).MarkDirty();
                    _someProperty = value;
                }
            }
        }

        public TestItem1(Serial serial) : base(serial)
        {
        }

        public override void Serialize(IGenericWriter writer)
        {
            var savePosition = ((Server.ISerializable)this).SavePosition;
            if (savePosition > -1)
            {
                writer.Seek(savePosition, System.IO.SeekOrigin.Begin);
                return;
            }
            writer.WriteEncodedInt(_version);
            writer.Write(_someProperty);
        }

        public override void Deserialize(IGenericReader reader)
        {
            var version = reader.ReadEncodedInt();
            if (version < 1)
            {
                OldDeserialize(reader, version);
                ((Server.ISerializable)this).MarkDirty();
                return;
            }
            SomeProperty = reader.ReadEntityList<Server.Item>();
        }
    }
}
```

And this:
```json
{
  "version": 1,
  "type": "TestItem1",
  "properties": [
    {
      "name": "SomeProperty",
      "type": "System.Collections.Generic.List\u003CServer.Item\u003E",
      "rule": "ListMigrationRule",
      "ruleArguments": [
        "Server.Item",
        "SerializableInterfaceMigrationRule"
      ]
    }
  ]
}
```
2021-05-23 21:06:23 -07:00

70 lines
1.5 KiB
YAML

name: 'Build'
trigger:
- main
variables:
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
DOTNET_SYSTEM_GLOBALIZATION_INVARIANT: 1
jobs:
- job: BuildWindows
displayName: 'Windows Server 2019'
pool:
vmImage: 'windows-latest'
steps:
- task: UseDotNet@2
displayName: 'Install .NET 5'
inputs:
packageType: sdk
version: 5.0.203
- task: NuGetAuthenticate@0
- script: ./publish.cmd Release win
displayName: 'Build'
- script: dotnet test --no-restore
displayName: 'Test'
- job: BuildLinux
strategy:
matrix:
'CentOS 8':
containerImage: centos:8
os: centos.8
'CentOS 7':
containerImage: centos:7
os: centos.7
'Debian 10':
containerImage: mcr.microsoft.com/dotnet/sdk:5.0-buster-slim
os: debian.10
# 'Debian 11':
# containerImage: amd64/buildpack-deps:bullseye
# os: debian.11-x64
'Ubuntu 20':
containerImage: mcr.microsoft.com/dotnet/sdk:5.0-focal
os: ubuntu.20.04
'Fedora 32':
containerImage: fedora:32
os: fedora.32
'Fedora 33':
containerImage: fedora:33
os: fedora.33
displayName: Linux
pool:
vmImage: 'ubuntu-latest'
container: $[ variables['containerImage'] ]
steps:
- task: UseDotNet@2
displayName: 'Install .NET 5'
inputs:
packageType: sdk
version: 5.0.203
- task: NuGetAuthenticate@0
- script: ./publish.cmd Release $(os)
displayName: 'Build'
- script: dotnet test --no-restore
displayName: 'Test'