From 481a58e8df3bdb12cccf95426faa4c56cf5929a6 Mon Sep 17 00:00:00 2001 From: Viktor Hofer Date: Sat, 7 Oct 2017 12:12:03 +0200 Subject: [PATCH] Make one more exception serializable some code styling --- .../shared/System/NotFiniteNumberException.cs | 10 +++++----- .../CompilerServices/RuntimeWrappedException.cs | 20 +++++++++----------- .../shared/System/Text/DecoderExceptionFallback.cs | 7 +++++++ .../shared/System/Threading/ThreadStartException.cs | 2 +- 4 files changed, 22 insertions(+), 17 deletions(-) diff --git a/src/mscorlib/shared/System/NotFiniteNumberException.cs b/src/mscorlib/shared/System/NotFiniteNumberException.cs index 259248f..b9c9af0 100644 --- a/src/mscorlib/shared/System/NotFiniteNumberException.cs +++ b/src/mscorlib/shared/System/NotFiniteNumberException.cs @@ -26,27 +26,27 @@ namespace System HResult = HResults.COR_E_NOTFINITENUMBER; } - public NotFiniteNumberException(String message) + public NotFiniteNumberException(string message) : base(message) { _offendingNumber = 0; HResult = HResults.COR_E_NOTFINITENUMBER; } - public NotFiniteNumberException(String message, double offendingNumber) + public NotFiniteNumberException(string message, double offendingNumber) : base(message) { _offendingNumber = offendingNumber; HResult = HResults.COR_E_NOTFINITENUMBER; } - public NotFiniteNumberException(String message, Exception innerException) + public NotFiniteNumberException(string message, Exception innerException) : base(message, innerException) { HResult = HResults.COR_E_NOTFINITENUMBER; } - public NotFiniteNumberException(String message, double offendingNumber, Exception innerException) + public NotFiniteNumberException(string message, double offendingNumber, Exception innerException) : base(message, innerException) { _offendingNumber = offendingNumber; @@ -61,7 +61,7 @@ namespace System public override void GetObjectData(SerializationInfo info, StreamingContext context) { base.GetObjectData(info, context); - info.AddValue("OffendingNumber", _offendingNumber, typeof(Int32)); + info.AddValue("OffendingNumber", _offendingNumber, typeof(int)); } public double OffendingNumber diff --git a/src/mscorlib/shared/System/Runtime/CompilerServices/RuntimeWrappedException.cs b/src/mscorlib/shared/System/Runtime/CompilerServices/RuntimeWrappedException.cs index af3b0c9..72996c6 100644 --- a/src/mscorlib/shared/System/Runtime/CompilerServices/RuntimeWrappedException.cs +++ b/src/mscorlib/shared/System/Runtime/CompilerServices/RuntimeWrappedException.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; -using System.Diagnostics.Contracts; using System.Runtime.Serialization; namespace System.Runtime.CompilerServices @@ -15,29 +13,29 @@ namespace System.Runtime.CompilerServices [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")] public sealed class RuntimeWrappedException : Exception { - private Object _wrappedException; // EE expects this name + private object _wrappedException; // EE expects this name // Not an api but has to be public as System.Linq.Expression invokes this through Reflection when an expression // throws an object that doesn't derive from Exception. - public RuntimeWrappedException(Object thrownObject) + public RuntimeWrappedException(object thrownObject) : base(SR.RuntimeWrappedException) { HResult = HResults.COR_E_RUNTIMEWRAPPED; _wrappedException = thrownObject; } - public override void GetObjectData(SerializationInfo info, StreamingContext context) + private RuntimeWrappedException(SerializationInfo info, StreamingContext context) + : base(info, context) { - base.GetObjectData(info, context); - info.AddValue("WrappedException", _wrappedException, typeof(object)); + _wrappedException = info.GetValue("WrappedException", typeof(object)); } - internal RuntimeWrappedException(SerializationInfo info, StreamingContext context) - : base(info, context) + public override void GetObjectData(SerializationInfo info, StreamingContext context) { - _wrappedException = info.GetValue("WrappedException", typeof(object)); + base.GetObjectData(info, context); + info.AddValue("WrappedException", _wrappedException, typeof(object)); } - public Object WrappedException => _wrappedException; + public object WrappedException => _wrappedException; } } diff --git a/src/mscorlib/shared/System/Text/DecoderExceptionFallback.cs b/src/mscorlib/shared/System/Text/DecoderExceptionFallback.cs index 26d604a..9fd6ef8 100644 --- a/src/mscorlib/shared/System/Text/DecoderExceptionFallback.cs +++ b/src/mscorlib/shared/System/Text/DecoderExceptionFallback.cs @@ -4,6 +4,7 @@ using System; using System.Globalization; +using System.Runtime.Serialization; namespace System.Text { @@ -98,6 +99,8 @@ namespace System.Text } // Exception for decoding unknown byte sequences. + [Serializable] + [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")] public sealed class DecoderFallbackException : ArgumentException { private byte[] _bytesUnknown = null; @@ -128,6 +131,10 @@ namespace System.Text _index = index; } + private DecoderFallbackException(SerializationInfo serializationInfo, StreamingContext streamingContext) + { + } + public byte[] BytesUnknown { get diff --git a/src/mscorlib/shared/System/Threading/ThreadStartException.cs b/src/mscorlib/shared/System/Threading/ThreadStartException.cs index c6b180a..5172555 100644 --- a/src/mscorlib/shared/System/Threading/ThreadStartException.cs +++ b/src/mscorlib/shared/System/Threading/ThreadStartException.cs @@ -22,7 +22,7 @@ namespace System.Threading HResult = HResults.COR_E_THREADSTART; } - internal ThreadStartException(SerializationInfo info, StreamingContext context) + private ThreadStartException(SerializationInfo info, StreamingContext context) : base(info, context) { } -- 2.7.4