Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Easily swap between common .NET serializer frameworks.

License

NotificationsYou must be signed in to change notification settings

BrannonKing/CommonSerializer

Repository files navigation

This library collection provides a common interface for common .NET serialization engines. It allows for quickly switching between the various serializers for comparing performance, features, etc.

These serializers are supported:

  1. Newtonsoft Json.NET
  2. MsgPack.CLI
  3. Protobuf-net
  4. Jil
  5. PowerJSON (built from fastJSON)

If there are others that you want supported, please file an issue requesting that.

The first three serializers listed support a feature for partial serialization. Consider that you might want to deserialize an outer object first so that you can determine the right data type for some inner object. The recommended method for accomplishing this works like this. You deserialize the thing twice -- the second time after you know the right data type:

[DataContract]publicclassRemoteProcedureCall// deserialize me first{[DataMember(Order=1)]publicstringMethodName{get;set;}}[DataContract]publicclassRemoteProcedureCall<T>:RemoteProcedureCall{[DataMember(Order=1)]publicTArguments{get;set;}}

The interface supports a method to register inheritors:RegisterSubtype. That will be necessary for serializers like Protobuf-net (or you can reference the Protobuf-net assembly directly and use its attributes).

However, you can use partial serialization like this:

[DataContract]publicclassRemoteProcedureCall{[DataMember(Order=1)]publicstringMethodName{get;set;}[DataMember(Order=2)]publicISerializedContainerArguments{get;set;}}...var serializer=newProtobufCommonSerializer();varmsg=newRemoteProcedureCall{MethodName="method"};msg.Arguments=serializer.GenerateContainer();serializer.Serialize(msg.Arguments,myFirstArgument);serializer.Serialize(msg.Arguments,mySecondArgument);serializer.Serialize(targetStream,msg);// and similarly for the reversevarmsg2=serializer.Deserialize<RemoteProcedureCall>(targetStream);varargument1=serializer.Deserialize<MyFirstArgumentType>(msg2.Arguments);

About

Easily swap between common .NET serializer frameworks.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp