#if MONO
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Runtime.ExceptionServices;
using System.Globalization;
using System.Runtime;
using System.Runtime.Serialization;
using System.Security;
namespace System
{
/// Represents one or more errors that occur during application execution.
[__DynamicallyInvokable, DebuggerDisplay("Count = {InnerExceptionCount}")]
[Serializable]
public class AggregateException : Exception
{
private ReadOnlyCollection m_innerExceptions;
/// Gets a read-only collection of the instances that caused the current exception.
/// Returns a read-only collection of the instances that caused the current exception.
[__DynamicallyInvokable]
public ReadOnlyCollection InnerExceptions
{
[__DynamicallyInvokable, TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
get
{
return this.m_innerExceptions;
}
}
private int InnerExceptionCount
{
get
{
return this.InnerExceptions.Count;
}
}
/// Initializes a new instance of the class with a system-supplied message that describes the error.
[__DynamicallyInvokable]
public AggregateException()
: base("AggregateException_ctor_DefaultMessage")
{
this.m_innerExceptions = new ReadOnlyCollection(new Exception[0]);
}
/// Initializes a new instance of the class with a specified message that describes the error.
/// The message that describes the exception. The caller of this constructor is required to ensure that this string has been localized for the current system culture.
[__DynamicallyInvokable]
public AggregateException(string message)
: base(message)
{
this.m_innerExceptions = new ReadOnlyCollection(new Exception[0]);
}
/// Initializes a new instance of the class with a specified error message and a reference to the inner exception that is the cause of this exception.
/// The message that describes the exception. The caller of this constructor is required to ensure that this string has been localized for the current system culture.
/// The exception that is the cause of the current exception. If the parameter is not null, the current exception is raised in a catch block that handles the inner exception.
/// The argument is null.
[__DynamicallyInvokable]
public AggregateException(string message, Exception innerException)
: base(message, innerException)
{
if (innerException == null)
{
throw new ArgumentNullException("innerException");
}
this.m_innerExceptions = new ReadOnlyCollection(new Exception[]
{
innerException
});
}
/// Initializes a new instance of the class with references to the inner exceptions that are the cause of this exception.
/// The exceptions that are the cause of the current exception.
/// The argument is null.
/// An element of is null.
[__DynamicallyInvokable]
public AggregateException(IEnumerable innerExceptions)
: this("AggregateException_ctor_DefaultMessage", innerExceptions)
{
}
/// Initializes a new instance of the class with references to the inner exceptions that are the cause of this exception.
/// The exceptions that are the cause of the current exception.
/// The argument is null.
/// An element of is null.
[__DynamicallyInvokable]
public AggregateException(params Exception[] innerExceptions)
: this("AggregateException_ctor_DefaultMessage", innerExceptions)
{
}
/// Initializes a new instance of the class with a specified error message and references to the inner exceptions that are the cause of this exception.
/// The error message that explains the reason for the exception.
/// The exceptions that are the cause of the current exception.
/// The argument is null.
/// An element of is null.
[__DynamicallyInvokable]
public AggregateException(string message, IEnumerable innerExceptions)
: this(message, (innerExceptions as IList) ?? ((innerExceptions == null) ? null : new List(innerExceptions)))
{
}
/// Initializes a new instance of the class with a specified error message and references to the inner exceptions that are the cause of this exception.
/// The error message that explains the reason for the exception.
/// The exceptions that are the cause of the current exception.
/// The argument is null.
/// An element of is null.
[__DynamicallyInvokable]
public AggregateException(string message, params Exception[] innerExceptions)
: this(message, (IList)innerExceptions)
{
}
internal AggregateException(IEnumerable innerExceptionInfos)
: this("AggregateException_ctor_DefaultMessage", innerExceptionInfos)
{
}
internal AggregateException(string message, IEnumerable innerExceptionInfos)
: this(message, (innerExceptionInfos as IList) ?? ((innerExceptionInfos == null) ? null : new List(innerExceptionInfos)))
{
}
/// Initializes a new instance of the class with serialized data.
/// The object that holds the serialized object data.
/// The contextual information about the source or destination.
/// The argument is null.
/// The exception could not be deserialized correctly.
[SecurityCritical]
protected AggregateException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
if (info == null)
{
throw new ArgumentNullException("info");
}
Exception[] array = info.GetValue("InnerExceptions", typeof(Exception[])) as Exception[];
if (array == null)
{
throw new SerializationException("AggregateException_DeserializationFailure");
}
this.m_innerExceptions = new ReadOnlyCollection(array);
}
/// Initializes a new instance of the class with serialized data.
/// The object that holds the serialized object data.
/// The contextual information about the source or destination.
/// The argument is null.
[SecurityCritical]
public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
if (info == null)
{
throw new ArgumentNullException("info");
}
base.GetObjectData(info, context);
Exception[] array = new Exception[this.m_innerExceptions.Count];
this.m_innerExceptions.CopyTo(array, 0);
info.AddValue("InnerExceptions", array, typeof(Exception[]));
}
/// Returns the that is the root cause of this exception.
/// Returns the that is the root cause of this exception.
[__DynamicallyInvokable]
public override Exception GetBaseException()
{
Exception ex = this;
AggregateException ex2 = this;
while (ex2 != null && ex2.InnerExceptions.Count == 1)
{
ex = ex.InnerException;
ex2 = (ex as AggregateException);
}
return ex;
}
/// Invokes a handler on each contained by this .
/// The predicate to execute for each exception. The predicate accepts as an argument the to be processed and returns a Boolean to indicate whether the exception was handled.
/// The argument is null.
/// An exception contained by this was not handled.
[__DynamicallyInvokable]
public void Handle(Func predicate)
{
if (predicate == null)
{
throw new ArgumentNullException("predicate");
}
List list = null;
for (int i = 0; i < this.m_innerExceptions.Count; i++)
{
if (!predicate(this.m_innerExceptions[i]))
{
if (list == null)
{
list = new List();
}
list.Add(this.m_innerExceptions[i]);
}
}
if (list != null)
{
throw new AggregateException(this.Message, list);
}
}
/// Flattens an instances into a single, new instance.
/// A new, flattened .
[__DynamicallyInvokable]
public AggregateException Flatten()
{
List list = new List();
List list2 = new List();
list2.Add(this);
int num = 0;
while (list2.Count > num)
{
IList innerExceptions = list2[num++].InnerExceptions;
for (int i = 0; i < innerExceptions.Count; i++)
{
Exception ex = innerExceptions[i];
if (ex != null)
{
AggregateException ex2 = ex as AggregateException;
if (ex2 != null)
{
list2.Add(ex2);
}
else
{
list.Add(ex);
}
}
}
}
return new AggregateException(this.Message, list);
}
/// Creates and returns a string representation of the current .
/// A string representation of the current exception.
[__DynamicallyInvokable]
public override string ToString()
{
string text = base.ToString();
for (int i = 0; i < this.m_innerExceptions.Count; i++)
{
text = string.Format(CultureInfo.InvariantCulture, "AggregateException_ToString", new object[]
{
text,
Environment.NewLine,
i,
this.m_innerExceptions[i].ToString(),
"<---",
Environment.NewLine
});
}
return text;
}
private AggregateException(string message, IList innerExceptions)
: base(message, (innerExceptions != null && innerExceptions.Count > 0) ? innerExceptions[0] : null)
{
if (innerExceptions == null)
{
throw new ArgumentNullException("innerExceptions");
}
Exception[] array = new Exception[innerExceptions.Count];
for (int i = 0; i < array.Length; i++)
{
array[i] = innerExceptions[i];
if (array[i] == null)
{
throw new ArgumentException("AggregateException_ctor_InnerExceptionNull");
}
}
this.m_innerExceptions = new ReadOnlyCollection(array);
}
private AggregateException(string message, IList innerExceptionInfos)
: base(message, (innerExceptionInfos != null && innerExceptionInfos.Count > 0 && innerExceptionInfos[0] != null) ? innerExceptionInfos[0].SourceException : null)
{
if (innerExceptionInfos == null)
{
throw new ArgumentNullException("innerExceptionInfos");
}
Exception[] array = new Exception[innerExceptionInfos.Count];
for (int i = 0; i < array.Length; i++)
{
ExceptionDispatchInfo exceptionDispatchInfo = innerExceptionInfos[i];
if (exceptionDispatchInfo != null)
{
array[i] = exceptionDispatchInfo.SourceException;
}
if (array[i] == null)
{
throw new ArgumentException("AggregateException_ctor_InnerExceptionNull");
}
}
this.m_innerExceptions = new ReadOnlyCollection(array);
}
}
}
#endif