Kittyfisto / SharpRemote

A .NET remoting library
MIT License
12 stars 5 forks source link

Introduce type-surrogates #26

Open Kittyfisto opened 7 years ago

Kittyfisto commented 7 years ago

It should be possible to define and create type-surrogates that are used in place of the actual types in an object graph:

    class A { 
        public A(string foo) { Foo = foo; }
        public readonly string Foo;
    }

    [SurrogateFor(typeof(A))]
    class ASurrogate
    {
        [DataMember] public string Foo;

        public static implicit operator A(ASurrogate value) { return new A(value.Foo); }
        public static implicit operator ASurrogate(A value) { return new ASurrogate{Foo = value.Foo}; }
    }

Every time SharpRemote tries to serialize an object of type A, its value should be converted to a ASurrogate and then serialized (as well as vice verca).

Kittyfisto commented 6 years ago

The introduction of type surrogates should make serializers for each built-in type obsolete and simplify the introduction of additional serializers as there only needs to be one surrogate (instead of one built-in serializer path per serializer).

Kittyfisto commented 6 years ago

It should be possible to create generic type surrogates for open types (such as IEnumerable<>). If such a type is defined, then it can be expected that it has the same number of parameters with identical type constraints (because a conversion to and from is needed).

Kittyfisto commented 6 years ago

The old serializer architecture will not support type surrogates, but the new architecture (which should ship in January 2018) will: Both XmlSerializer and BinarySerializer2 will support this feature upon initial release.

Kittyfisto commented 6 years ago

Built-in serializers should support only array and list implementations and all other collections shall be implemented via type surrogates (which aren't tied to any specific serializer anymore).