/* * ExceptionalDictionary.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 { /// /// Represents a collection of keys and values, with its own exception type. /// /// /// /// The type of the keys in the dictionary. /// /// /// /// The type of the values in the dictionary. /// /// /// /// Sample usage: /// public class A : ExceptionalDictionary <int, 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. /// } /// /// [global::System.Serializable] public class ExceptionalDictionary : Dictionary { /// /// Initializes a new instance of the ExceptionalDictionary /// class that is empty, has the default initial capacity, and uses the default quality /// comparer for the key type. /// public ExceptionalDictionary() : base() { } /// /// Initializes a new instance of the ExceptionalDictionary /// class that is empty, has the specified initial capacity, and uses the default quality /// comparer for the key type. /// /// /// /// The initial number of elements that the ExceptionalDictionary /// can contain. /// /// public ExceptionalDictionary(int capacity) : base(capacity) { } /// /// Initializes a new instance of the ExceptionalDictionary /// class that is empty, has the default initial capacity, and uses the specified quality /// comparer for the key type. /// /// /// /// The T:System.Collections.Generic.IEqualityComparer implementation to use when comparaing /// keys, or null to use the default T:System.Collections.Generic.IEqualityComparer for the /// type of the key. /// /// public ExceptionalDictionary(IEqualityComparer comparer) : base(comparer) { } /// /// Initializes a new instance of the ExceptionalDictionary /// class initialized to the settings and contents of the specified /// System.Collections.Generic.IDictionary-sporting object. /// /// /// /// The System.Collections.Generic.IDictionary whose elements are copied /// to the new ExceptionalDictionary. /// /// public ExceptionalDictionary(IDictionary dictionary) : base(dictionary) { } /// /// Initializes a new instance of the ExceptionalDictionary /// class that is empty, has the specified initial capacity, and uses the specified quality /// comparer for the key type. /// /// /// /// The initial number of elements that the ExceptionalDictionary /// can contain. /// /// /// /// The T:System.Collections.Generic.IEqualityComparer implementation to use when comparing /// keys, or null to use the default T:System.Collections.Generic.IEqualityComparer for the /// type of the key. /// /// public ExceptionalDictionary(int capacity, IEqualityComparer comparer) : base(capacity, comparer) { } /// /// Initializes a new instance of the ExceptionalDictionary /// class with the specified serialization information and context. /// /// /// /// A System.Runtime.Serialization.SerializationInfo object containing the information /// required to serialize the ExceptionalDictionary. /// /// /// /// A System.Runtime.Serialization.StreamingContext structure containing the source and /// destination of the serialized stream associated with the /// DTS.UtilitiesExceptionalDictionary. /// /// public ExceptionalDictionary(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) : base(info, context) { } /// /// Initializes a new instance of the ExceptionalDictionary /// class with the specified dictionary key/value pairs and the specified comparer implementation. /// /// /// /// The System.Collections.Generic.IDictionary whose elements are copied to the new /// ExceptionalDictionary. /// /// /// /// The T:System.Collections.Generic.IEqualityComparer implementation to use when comparing keys, or null to use the default /// T:System.Collections.Generic.IEqualityComparer for the type of the key. /// /// public ExceptionalDictionary(IDictionary dictionary, IEqualityComparer comparer) : base(dictionary, comparer) { } /// /// A representation of the DerivedClass.Exception class. /// 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) { } } } }