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[])));
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; }
}
}