From: Justin Van Patten Date: Fri, 5 Jan 2018 04:42:58 +0000 (-0800) Subject: Address ReflectionTypeLoadException feedback (#15738) X-Git-Tag: accepted/tizen/base/20180629.140029~205 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6faa6bb6de44693b7da95c61c0f22df89ef8e373;p=platform%2Fupstream%2Fcoreclr.git Address ReflectionTypeLoadException feedback (#15738) * Address ReflectionTypeLoadException feedback Address additional minor feedback from #15711: - Share the code for `Message` and `ToString` - Remove trailing `NewLine` from resulting string - Pass initial base string to `StringBuilder..ctor` - Cache the exceptions array in a local (passed-in as a parameter) - Move methods below properties - Remove trailing whitespace --- diff --git a/src/mscorlib/shared/System/Reflection/ReflectionTypeLoadException.cs b/src/mscorlib/shared/System/Reflection/ReflectionTypeLoadException.cs index d78c068..5011c50 100644 --- a/src/mscorlib/shared/System/Reflection/ReflectionTypeLoadException.cs +++ b/src/mscorlib/shared/System/Reflection/ReflectionTypeLoadException.cs @@ -27,7 +27,7 @@ namespace System.Reflection HResult = HResults.COR_E_REFLECTIONTYPELOAD; } - private ReflectionTypeLoadException(SerializationInfo info, StreamingContext context) + private ReflectionTypeLoadException(SerializationInfo info, StreamingContext context) : base(info, context) { LoaderExceptions = (Exception[])(info.GetValue("Exceptions", typeof(Exception[]))); @@ -40,48 +40,34 @@ namespace System.Reflection info.AddValue("Exceptions", LoaderExceptions, typeof(Exception[])); } - public override string Message + public Type[] Types { get; } + + public Exception[] LoaderExceptions { get; } + + public override string Message => CreateString(isMessage: true); + + public override string ToString() => CreateString(isMessage: false); + + private string CreateString(bool isMessage) { - get - { - if (LoaderExceptions == null || LoaderExceptions.Length == 0) - { - return base.Message; - } + string baseValue = isMessage ? base.Message : base.ToString(); - StringBuilder text = new StringBuilder(); - text.AppendLine(base.Message); - foreach (Exception e in LoaderExceptions) - { - if (e != null) - { - text.AppendLine(e.Message); - } - } - return text.ToString(); + Exception[] exceptions = LoaderExceptions; + if (exceptions == null || exceptions.Length == 0) + { + return baseValue; } - } - public override string ToString() - { - StringBuilder text = new StringBuilder(); - text.AppendLine(base.ToString()); - if (LoaderExceptions != null) + var text = new StringBuilder(baseValue); + foreach (Exception e in exceptions) { - foreach (Exception e in LoaderExceptions) + if (e != null) { - if (e != null) - { - text.AppendLine(e.ToString()); - } + text.AppendLine(); + text.Append(isMessage ? e.Message : e.ToString()); } } - return text.ToString(); } - - public Type[] Types { get; } - - public Exception[] LoaderExceptions { get; } } }