102 lines
2.8 KiB
C#
102 lines
2.8 KiB
C#
/*
|
|
* ExceptionalList.cs
|
|
*
|
|
* Copyright © 2009
|
|
* Diversified Technical Systems, Inc.
|
|
* All Rights Reserved
|
|
*/
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.Linq;
|
|
using System.Text;
|
|
|
|
namespace DTS.Common.Utilities
|
|
{
|
|
/// <summary>
|
|
/// A version of <see cref="T:List"/> that provides its own exception type.
|
|
/// </summary>
|
|
///
|
|
/// <typeparam name="T">
|
|
/// The type of object contained by this list.
|
|
/// </typeparam>
|
|
///
|
|
/// <remarks>
|
|
/// Sample usage:
|
|
/// public class A : ExceptionalList <int>
|
|
/// {
|
|
/// public void ScrewItUp( )
|
|
/// {
|
|
/// private bool error = true;
|
|
/// if ( error ) throw new A.Exception( "Class A-specific screwup." );
|
|
/// }
|
|
/// }
|
|
///
|
|
/// ...
|
|
///
|
|
/// try
|
|
/// {
|
|
/// A.ScrewItUp( );
|
|
/// B.ScrewItUp( );
|
|
/// C.ScrewItUp( );
|
|
/// }
|
|
/// catch ( A.Exception ex )
|
|
/// {
|
|
/// // Can pick A's exceptions out of a crowd, or not and just treat it
|
|
/// // polymorphically as a System.Exception.
|
|
/// }
|
|
/// </remarks>
|
|
///
|
|
[global::System.Serializable]
|
|
public class ExceptionalList<T> : List<T>
|
|
{
|
|
/// <summary>
|
|
/// Initialize an instance of the ExceptionalList class.
|
|
/// </summary>
|
|
public ExceptionalList()
|
|
: base()
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// Initialize an instance of the ExceptionalList class.
|
|
/// </summary>
|
|
///
|
|
/// <param name="capacity">
|
|
/// The number of elements that the list can initially store.
|
|
/// </param>
|
|
///
|
|
public ExceptionalList(int capacity)
|
|
: base(capacity)
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// Initialize an instance of the ExceptionalList class.
|
|
/// </summary>
|
|
///
|
|
/// <param name="collection">
|
|
/// The collection whose elements are copied to the new list.
|
|
/// </param>
|
|
///
|
|
public ExceptionalList(IEnumerable<T> collection)
|
|
: base(collection)
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// A representation of the DerivedClass.Exception class.
|
|
/// </summary>
|
|
public class Exception : ApplicationException
|
|
{
|
|
public Exception() { }
|
|
public Exception(string msg) : base(msg) { }
|
|
public Exception(string msg, System.Exception innerEx) : base(msg, innerEx) { }
|
|
protected Exception(
|
|
System.Runtime.Serialization.SerializationInfo info,
|
|
System.Runtime.Serialization.StreamingContext context) : base(info, context) { }
|
|
}
|
|
}
|
|
}
|