1 // -----------------------------------------------------------------------
\r
2 // Copyright (c) Microsoft Corporation. All rights reserved.
\r
3 // -----------------------------------------------------------------------
\r
5 using Microsoft.Internal;
\r
7 namespace System.ComponentModel.Composition.Primitives
\r
9 // As most objects that implement ICompositionElement (such as Export, ComposablePart,
\r
10 // ComposablePartCatalog, etc) are not serializable, this class is used as a serializable
\r
11 // placeholder for these types when ICompositionElement is used within serializable types,
\r
12 // such as CompositionException, CompositionIssue, etc.
\r
14 internal class SerializableCompositionElement : ICompositionElement
\r
16 private readonly string _displayName;
\r
17 private readonly ICompositionElement _origin;
\r
19 public SerializableCompositionElement(string displayName, ICompositionElement origin)
\r
22 Assumes.IsTrue(origin == null || origin.GetType().IsSerializable);
\r
24 this._displayName = displayName ?? string.Empty;
\r
25 this._origin = origin;
\r
28 public string DisplayName
\r
30 get { return this._displayName; }
\r
33 public ICompositionElement Origin
\r
35 get { return this._origin; }
\r
38 public override string ToString()
\r
40 return this.DisplayName;
\r
43 public static ICompositionElement FromICompositionElement(ICompositionElement element)
\r
45 if (element == null)
\r
46 { // Null is always serializable
\r
51 ICompositionElement origin = FromICompositionElement(element.Origin);
\r
53 // Otherwise, we need to create a serializable wrapper
\r
54 return new SerializableCompositionElement(element.DisplayName, origin);
\r