// ----------------------------------------------------------------------- // Copyright (c) Microsoft Corporation. All rights reserved. // ----------------------------------------------------------------------- using System; using System.ComponentModel.Composition.Hosting; using System.ComponentModel.Composition.Primitives; using System.Diagnostics; using System.Globalization; using System.Security.Permissions; using Microsoft.Internal; namespace System.ComponentModel.Composition { /// /// Represents an error that occurs during composition in a . /// [Serializable] [DebuggerTypeProxy(typeof(CompositionErrorDebuggerProxy))] public class CompositionError : ICompositionError { private readonly CompositionErrorId _id; private readonly string _description; private readonly Exception _exception; private readonly ICompositionElement _element; /// /// Initializes a new instance of the class /// with the specified error message. /// /// /// A containing a message that describes the /// ; or to set the /// property to an empty string (""). /// public CompositionError(string message) : this(CompositionErrorId.Unknown, message, (ICompositionElement)null, (Exception)null) { } /// /// Initializes a new instance of the class /// with the specified error message and composition element that is the /// cause of the composition error. /// /// /// The that is the cause of the /// ; or to set /// the property to /// . /// /// /// A containing a message that describes the /// ; or to set the /// property to an empty string (""). /// public CompositionError(string message, ICompositionElement element) : this(CompositionErrorId.Unknown, message, element, (Exception)null) { } /// /// Initializes a new instance of the class /// with the specified error message and exception that is the cause of the /// composition error. /// /// /// A containing a message that describes the /// ; or to set the /// property to an empty string (""). /// /// /// The that is the underlying cause of the /// ; or to set /// the property to . /// public CompositionError(string message, Exception exception) : this(CompositionErrorId.Unknown, message, (ICompositionElement)null, exception) { } /// /// Initializes a new instance of the class /// with the specified error message, and composition element and exception that /// is the cause of the composition error. /// /// /// A containing a message that describes the /// ; or to set the /// property to an empty string (""). /// /// /// The that is the cause of the /// ; or to set /// the property to /// . /// /// /// The that is the underlying cause of the /// ; or to set /// the property to . /// public CompositionError(string message, ICompositionElement element, Exception exception) : this(CompositionErrorId.Unknown, message, element, exception) { } internal CompositionError(CompositionErrorId id, string description, ICompositionElement element, Exception exception) { _id = id; _description = description ?? string.Empty; _element = element; _exception = exception; } /// /// Gets the composition element that is the cause of the error. /// /// /// The that is the cause of the /// . The default is . /// public ICompositionElement Element { get { return _element; } } /// /// Gets the message that describes the composition error. /// /// /// A containing a message that describes the /// . /// public string Description { get { return _description; } } /// /// Gets the exception that is the underlying cause of the composition error. /// /// /// The that is the underlying cause of the /// . The default is . /// public Exception Exception { get { return _exception; } } CompositionErrorId ICompositionError.Id { get { return _id; } } Exception ICompositionError.InnerException { get { return Exception; } } /// /// Returns a string representation of the composition error. /// /// /// A containing the property. /// public override string ToString() { return this.Description; } internal static CompositionError Create(CompositionErrorId id, string format, params object[] parameters) { return Create(id, (ICompositionElement)null, (Exception)null, format, parameters); } internal static CompositionError Create(CompositionErrorId id, ICompositionElement element, string format, params object[] parameters) { return Create(id, element, (Exception)null, format, parameters); } internal static CompositionError Create(CompositionErrorId id, ICompositionElement element, Exception exception, string format, params object[] parameters) { return new CompositionError(id, string.Format(CultureInfo.CurrentCulture, format, parameters), element, exception); } } }