Skip to content

Commit

Permalink
Recode Serializer.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
XiaoFeiDu committed Feb 8, 2022
1 parent bb77fdb commit cc8b55f
Show file tree
Hide file tree
Showing 21 changed files with 58 additions and 90 deletions.
4 changes: 2 additions & 2 deletions src/Zaabee.Binary/Zaabee.Binary.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<PropertyGroup>
<TargetFrameworks>netstandard2.0;netcoreapp3.1;net5.0;net6.0</TargetFrameworks>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageVersion>2022.12.0</PackageVersion>
<Version>2022.12.0</Version>
<PackageVersion>2022.14.0</PackageVersion>
<Version>2022.14.0</Version>
<Authors>Mutuduxf</Authors>
<Company>Mutuduxf</Company>
<PackageProjectUrl>https://github.com/PicoHex/Zaabee.Serializers/tree/master/src/Zaabee.Binary</PackageProjectUrl>
Expand Down
12 changes: 4 additions & 8 deletions src/Zaabee.DataContractSerializer/Serializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,14 @@ stream is null || stream.CanSeek && stream.Length is 0
: DataContractHelper.FromStream(type, stream);

public string ToXml<TValue>(TValue? value) =>
DataContractHelper.ToXml(value);
ToText(value);

public TValue? FromXml<TValue>(string? xml) =>
string.IsNullOrWhiteSpace(xml)
? default
: DataContractHelper.FromXml<TValue>(xml);
FromText<TValue>(xml);

public string ToXml(Type type, object? value) =>
DataContractHelper.ToXml(type, value);
ToText(type, value);

public object? FromXml(Type type, string? xml) =>
string.IsNullOrWhiteSpace(xml)
? default
: DataContractHelper.FromXml(type, xml);
FromText(type, xml);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<PropertyGroup>
<TargetFrameworks>netstandard2.0;netcoreapp3.1;net5.0;net6.0</TargetFrameworks>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageVersion>2022.12.0</PackageVersion>
<Version>2022.12.0</Version>
<PackageVersion>2022.14.0</PackageVersion>
<Version>2022.14.0</Version>
<Authors>Mutuduxf</Authors>
<Company>Mutuduxf</Company>
<PackageProjectUrl>https://github.com/PicoHex/Zaabee.Serializers/tree/master/src/Zaabee.DataContractSerializer</PackageProjectUrl>
Expand Down
12 changes: 4 additions & 8 deletions src/Zaabee.Jil/Serializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,14 @@ stream is null || stream.CanSeek && stream.Length is 0
: JilHelper.FromStream(type, stream, _options, _encoding);

public string ToJson<TValue>(TValue? value) =>
JilHelper.ToJson(value, _options);
ToText(value);

public TValue? FromJson<TValue>(string? json) =>
json.IsNullOrWhiteSpace()
? default
: JilHelper.FromJson<TValue>(json, _options);
FromText<TValue>(json);

public string ToJson(Type type, object? value) =>
JilHelper.ToJson(value, _options);
ToText(type, value);

public object? FromJson(Type type, string? json) =>
json.IsNullOrWhiteSpace()
? default
: JilHelper.FromJson(type, json, _options);
FromText(type, json);
}
4 changes: 2 additions & 2 deletions src/Zaabee.Jil/Zaabee.Jil.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageVersion>2022.12.0</PackageVersion>
<Version>2022.12.0</Version>
<PackageVersion>2022.14.0</PackageVersion>
<Version>2022.14.0</Version>
<Authors>Mutuduxf</Authors>
<Company>Mutuduxf</Company>
<PackageProjectUrl>https://github.com/PicoHex/Zaabee.Serializers/tree/master/src/Zaabee.Jil</PackageProjectUrl>
Expand Down
4 changes: 2 additions & 2 deletions src/Zaabee.MessagePack/Zaabee.MessagePack.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<PropertyGroup>
<TargetFrameworks>netstandard2.0;netcoreapp3.1;net5.0</TargetFrameworks>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageVersion>2022.12.0</PackageVersion>
<Version>2022.12.0</Version>
<PackageVersion>2022.14.0</PackageVersion>
<Version>2022.14.0</Version>
<Authors>Mutuduxf</Authors>
<Company>Mutuduxf</Company>
<PackageProjectUrl>https://github.com/PicoHex/Zaabee.Serializers/tree/master/src/Zaabee.MessagePack</PackageProjectUrl>
Expand Down
4 changes: 2 additions & 2 deletions src/Zaabee.MsgPack/Zaabee.MsgPack.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageVersion>2022.12.0</PackageVersion>
<Version>2022.12.0</Version>
<PackageVersion>2022.14.0</PackageVersion>
<Version>2022.14.0</Version>
<Authors>Mutuduxf</Authors>
<Company>Mutuduxf</Company>
<PackageProjectUrl>https://github.com/PicoHex/Zaabee.Serializers/tree/master/src/Zaabee.MsgPack</PackageProjectUrl>
Expand Down
12 changes: 4 additions & 8 deletions src/Zaabee.NewtonsoftJson/Serializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,14 @@ stream is null || stream.CanSeek && stream.Length is 0
: NewtonsoftJsonHelper.FromStream(type, stream, _settings, _encoding);

public string ToJson<TValue>(TValue? value) =>
NewtonsoftJsonHelper.ToJson(value, _settings);
ToText(value);

public TValue? FromJson<TValue>(string? json) =>
string.IsNullOrWhiteSpace(json)
? default
: NewtonsoftJsonHelper.FromJson<TValue>(json, _settings);
FromText<TValue>(json);

public string ToJson(Type type, object? value) =>
NewtonsoftJsonHelper.ToJson(type, value, _settings);
ToText(type, value);

public object? FromJson(Type type, string? json) =>
string.IsNullOrWhiteSpace(json)
? default
: NewtonsoftJsonHelper.FromJson(type, json, _settings);
FromText(type, json);
}
4 changes: 2 additions & 2 deletions src/Zaabee.NewtonsoftJson/Zaabee.NewtonsoftJson.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageVersion>2022.12.0</PackageVersion>
<Version>2022.12.0</Version>
<PackageVersion>2022.14.0</PackageVersion>
<Version>2022.14.0</Version>
<Authors>Mutuduxf</Authors>
<Company>Mutuduxf</Company>
<PackageProjectUrl>https://github.com/PicoHex/Zaabee.Serializers/tree/master/src/Zaabee.NewtonsoftJson</PackageProjectUrl>
Expand Down
4 changes: 2 additions & 2 deletions src/Zaabee.Protobuf/Zaabee.Protobuf.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<PropertyGroup>
<TargetFrameworks>netstandard2.0;netcoreapp3.1;net5.0</TargetFrameworks>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageVersion>2022.12.0</PackageVersion>
<Version>2022.12.0</Version>
<PackageVersion>2022.14.0</PackageVersion>
<Version>2022.14.0</Version>
<Authors>Mutuduxf</Authors>
<Company>Mutuduxf</Company>
<PackageProjectUrl>https://github.com/PicoHex/Zaabee.Serializers/tree/master/src/Zaabee.Protobuf</PackageProjectUrl>
Expand Down
12 changes: 4 additions & 8 deletions src/Zaabee.SharpYaml/Serializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,14 @@ public string ToText(Type type, object? value) =>
: SharpYamlHelper.FromYaml(type, text);

public string ToYaml<TValue>(TValue? value) =>
SharpYamlHelper.ToYaml(value);
ToText(value);

public TValue? FromYaml<TValue>(string? yaml) =>
string.IsNullOrWhiteSpace(yaml)
? default
: SharpYamlHelper.FromYaml<TValue>(yaml);
FromText<TValue>(yaml);

public string ToYaml(Type type, object? value) =>
SharpYamlHelper.ToYaml(type, value);
ToText(type, value);

public object? FromYaml(Type type, string? yaml) =>
string.IsNullOrWhiteSpace(yaml)
? default
: SharpYamlHelper.FromYaml(type, yaml);
FromText(type, yaml);
}
4 changes: 2 additions & 2 deletions src/Zaabee.SharpYaml/Zaabee.SharpYaml.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<PropertyGroup>
<TargetFrameworks>netstandard2.0;netcoreapp3.1;net5.0;net6.0</TargetFrameworks>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageVersion>2022.12.0</PackageVersion>
<Version>2022.12.0</Version>
<PackageVersion>2022.14.0</PackageVersion>
<Version>2022.14.0</Version>
<Authors>Mutuduxf</Authors>
<Company>Mutuduxf</Company>
<PackageProjectUrl>https://github.com/PicoHex/Zaabee.Serializers/tree/master/src/Zaabee.SharpYaml</PackageProjectUrl>
Expand Down
12 changes: 4 additions & 8 deletions src/Zaabee.SystemTextJson/Serializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,14 @@ public string ToText(Type type, object? value) =>
: SystemTextJsonHelper.FromJson(type, text, _options);

public string ToJson<TValue>(TValue? value) =>
SystemTextJsonHelper.ToJson(value, _options);
ToText(value);

public TValue? FromJson<TValue>(string? json) =>
string.IsNullOrWhiteSpace(json)
? default
: SystemTextJsonHelper.FromJson<TValue>(json, _options);
FromText<TValue>(json);

public string ToJson(Type type, object? value) =>
SystemTextJsonHelper.ToJson(type, value, _options);
ToText(type, value);

public object? FromJson(Type type, string? json) =>
string.IsNullOrWhiteSpace(json)
? default
: SystemTextJsonHelper.FromJson(type, json, _options);
FromText(type, json);
}
4 changes: 2 additions & 2 deletions src/Zaabee.SystemTextJson/Zaabee.SystemTextJson.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<PropertyGroup>
<TargetFrameworks>netstandard2.0;netcoreapp3.1;net5.0;net6.0</TargetFrameworks>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageVersion>2022.12.0</PackageVersion>
<Version>2022.12.0</Version>
<PackageVersion>2022.14.0</PackageVersion>
<Version>2022.14.0</Version>
<Authors>Mutuduxf</Authors>
<Company>Mutuduxf</Company>
<PackageProjectUrl>https://github.com/PicoHex/Zaabee.Serializers/tree/master/src/Zaabee.Protobuf</PackageProjectUrl>
Expand Down
12 changes: 4 additions & 8 deletions src/Zaabee.Utf8Json/Serializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,14 @@ stream is null || stream.CanSeek && stream.Length is 0
: Utf8JsonHelper.FromStream(type, stream, _resolver);

public string ToJson<TValue>(TValue? value) =>
Utf8JsonHelper.ToJson(value, _resolver);
ToText(value);

public TValue? FromJson<TValue>(string? json) =>
string.IsNullOrWhiteSpace(json)
? default
: Utf8JsonHelper.FromJson<TValue>(json, _resolver);
FromText<TValue>(json);

public string ToJson(Type type, object? value) =>
Utf8JsonHelper.ToJson(type, value, _resolver);
ToText(type, value);

public object? FromJson(Type type, string? json) =>
string.IsNullOrWhiteSpace(json)
? default
: Utf8JsonHelper.FromJson(type, json, _resolver);
FromText(type, json);
}
4 changes: 2 additions & 2 deletions src/Zaabee.Utf8Json/Zaabee.Utf8Json.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageVersion>2022.12.0</PackageVersion>
<Version>2022.12.0</Version>
<PackageVersion>2022.14.0</PackageVersion>
<Version>2022.14.0</Version>
<Authors>Mutuduxf</Authors>
<Company>Mutuduxf</Company>
<PackageProjectUrl>https://github.com/PicoHex/Zaabee.Serializers/tree/master/src/Zaabee.Utf8Json</PackageProjectUrl>
Expand Down
12 changes: 4 additions & 8 deletions src/Zaabee.Xml/Serializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,14 @@ stream is null || stream.CanSeek && stream.Length is 0
: XmlHelper.FromStream(type, stream);

public string ToXml<TValue>(TValue? value) =>
XmlHelper.ToXml(value);
ToText(value);

public TValue? FromXml<TValue>(string? xml) =>
string.IsNullOrWhiteSpace(xml)
? default
: XmlHelper.FromXml<TValue>(xml);
FromText<TValue>(xml);

public string ToXml(Type type, object? value) =>
XmlHelper.ToXml(type, value);
ToText(type, value);

public object? FromXml(Type type, string? xml) =>
string.IsNullOrWhiteSpace(xml)
? default
: XmlHelper.FromXml(type, xml);
FromText(type, xml);
}
4 changes: 2 additions & 2 deletions src/Zaabee.Xml/Zaabee.Xml.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<PropertyGroup>
<TargetFrameworks>netstandard2.0;netcoreapp3.1;net5.0;net6.0</TargetFrameworks>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageVersion>2022.12.0</PackageVersion>
<Version>2022.12.0</Version>
<PackageVersion>2022.14.0</PackageVersion>
<Version>2022.14.0</Version>
<Authors>Mutuduxf</Authors>
<Company>Mutuduxf</Company>
<PackageProjectUrl>https://github.com/PicoHex/Zaabee.Serializers/tree/master/src/Zaabee.Xml</PackageProjectUrl>
Expand Down
12 changes: 4 additions & 8 deletions src/Zaabee.YamlDotNet/Serializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,14 @@ public string ToText(Type type, object? value) =>
: YamlDotNetHelper.FromYaml(type, text);

public string ToYaml<TValue>(TValue? value) =>
YamlDotNetHelper.ToYaml(value);
ToText(value);

public TValue? FromYaml<TValue>(string? yaml) =>
string.IsNullOrWhiteSpace(yaml)
? default
: YamlDotNetHelper.FromYaml<TValue>(yaml);
FromText<TValue>(yaml);

public string ToYaml(Type type, object? value) =>
YamlDotNetHelper.ToYaml(value);
ToText(value);

public object? FromYaml(Type type, string? yaml) =>
string.IsNullOrWhiteSpace(yaml)
? default
: YamlDotNetHelper.FromYaml(type, yaml);
FromText(type, yaml);
}
4 changes: 2 additions & 2 deletions src/Zaabee.YamlDotNet/Zaabee.YamlDotNet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1</TargetFrameworks>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageVersion>2022.12.0</PackageVersion>
<Version>2022.12.0</Version>
<PackageVersion>2022.14.0</PackageVersion>
<Version>2022.14.0</Version>
<Authors>Mutuduxf</Authors>
<Company>Mutuduxf</Company>
<PackageProjectUrl>https://github.com/PicoHex/Zaabee.Serializers/tree/master/src/Zaabee.YamlDotNet</PackageProjectUrl>
Expand Down
4 changes: 2 additions & 2 deletions src/Zaabee.ZeroFormatter/Zaabee.ZeroFormatter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<PropertyGroup>
<TargetFrameworks>netstandard2.0;netcoreapp3.1;net5.0;net6.0</TargetFrameworks>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageVersion>2022.12.0</PackageVersion>
<Version>2022.12.0</Version>
<PackageVersion>2022.14.0</PackageVersion>
<Version>2022.14.0</Version>
<Authors>Mutuduxf</Authors>
<Company>Mutuduxf</Company>
<PackageProjectUrl>https://github.com/PicoHex/Zaabee.Serializers/tree/master/src/Zaabee.ZeroFormatter</PackageProjectUrl>
Expand Down

0 comments on commit cc8b55f

Please sign in to comment.