Skip to content
This repository has been archived by the owner on Aug 8, 2024. It is now read-only.

Commit

Permalink
fix encoding serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
EgorBo authored and marek-safar committed Nov 27, 2018
1 parent eeff01a commit 23d0b58
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
15 changes: 14 additions & 1 deletion src/Common/src/CoreLib/System/Text/DecoderReplacementFallback.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
// See the LICENSE file in the project root for more information.

using System.Diagnostics;
using System.Runtime.Serialization;

namespace System.Text
{
#if MONO
[System.Serializable]
#endif
public sealed class DecoderReplacementFallback : DecoderFallback, ISerializable
#else
public sealed class DecoderReplacementFallback : DecoderFallback
#endif
{
// Our variables
private String _strDefault;
Expand All @@ -19,6 +22,16 @@ public DecoderReplacementFallback() : this("?")
{
}

#if MONO
internal DecoderReplacementFallback(SerializationInfo info, StreamingContext context)
{
try { _strDefault = info.GetString("strDefault"); } // for old mono and .NET 4.x
catch { _strDefault = info.GetString("_strDefault"); }
}

void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context) => info.AddValue("strDefault", _strDefault);
#endif

public DecoderReplacementFallback(String replacement)
{
if (replacement == null)
Expand Down
15 changes: 14 additions & 1 deletion src/Common/src/CoreLib/System/Text/EncoderReplacementFallback.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@
using System;
using System.Runtime;
using System.Diagnostics;
using System.Runtime.Serialization;

namespace System.Text
{
#if MONO
[Serializable]
#endif
public sealed class EncoderReplacementFallback : EncoderFallback, ISerializable
#else
public sealed class EncoderReplacementFallback : EncoderFallback
#endif
{
// Our variables
private String _strDefault;
Expand All @@ -21,6 +24,16 @@ public EncoderReplacementFallback() : this("?")
{
}

#if MONO
internal EncoderReplacementFallback(SerializationInfo info, StreamingContext context)
{
try { _strDefault = info.GetString("strDefault"); } // for old mono and .NET 4.x
catch { _strDefault = info.GetString("_strDefault"); }
}

void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context) => info.AddValue("strDefault", _strDefault);
#endif

public EncoderReplacementFallback(String replacement)
{
// Must not be null
Expand Down

0 comments on commit 23d0b58

Please sign in to comment.