The Labs \ Source Viewer \ SSCLI \ System \ ObjectDisposedException

  1. // ==++==
  2. //
  3. //
  4. // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
  5. //
  6. // The use and distribution terms for this software are contained in the file
  7. // named license.txt, which can be found in the root of this distribution.
  8. // By using this software in any fashion, you are agreeing to be bound by the
  9. // terms of this license.
  10. //
  11. // You must not remove this notice, or any other, from this software.
  12. //
  13. //
  14. // ==--==
  15. namespace System
  16. {
  17.     using System;
  18.     using System.Runtime.Serialization;
  19.     using System.Globalization;
  20.     using System.Security.Permissions;
  21.    
  22.     /// <devdoc>
  23.     /// <para> The exception that is thrown when accessing an object that was
  24.     /// disposed.</para>
  25.     /// </devdoc>
  26.     [System.Runtime.InteropServices.ComVisible(true)]
  27.     [Serializable()]
  28.     public class ObjectDisposedException : InvalidOperationException
  29.     {
  30.         private string objectName;
  31.        
  32.         // This constructor should only be called by the EE (COMPlusThrow)
  33.         private ObjectDisposedException() : this(null, Environment.GetResourceString("ObjectDisposed_Generic"))
  34.         {
  35.         }
  36.        
  37.         public ObjectDisposedException(string objectName) : this(objectName, Environment.GetResourceString("ObjectDisposed_Generic"))
  38.         {
  39.         }
  40.        
  41.         public ObjectDisposedException(string objectName, string message) : base(message)
  42.         {
  43.             SetErrorCode(__HResults.COR_E_OBJECTDISPOSED);
  44.             this.objectName = objectName;
  45.         }
  46.        
  47.         public ObjectDisposedException(string message, Exception innerException) : base(message, innerException)
  48.         {
  49.             SetErrorCode(__HResults.COR_E_OBJECTDISPOSED);
  50.         }
  51.        
  52.         /// <devdoc>
  53.         /// <para>Gets the text for the message for this exception.</para>
  54.         /// </devdoc>
  55.         public override string Message {
  56.             get {
  57.                 string name = ObjectName;
  58.                 if (name == null || name.Length == 0)
  59.                     return base.Message;
  60.                 return base.Message + Environment.NewLine + String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("ObjectDisposed_ObjectName_Name"), name);
  61.             }
  62.         }
  63.        
  64.         public string ObjectName {
  65.             get {
  66.                 if (objectName == null)
  67.                     return String.Empty;
  68.                 return objectName;
  69.             }
  70.         }
  71.        
  72.         protected ObjectDisposedException(SerializationInfo info, StreamingContext context) : base(info, context)
  73.         {
  74.             objectName = info.GetString("ObjectName");
  75.         }
  76.        
  77.         [SecurityPermissionAttribute(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.SerializationFormatter)]
  78.         public override void GetObjectData(SerializationInfo info, StreamingContext context)
  79.         {
  80.             base.GetObjectData(info, context);
  81.             info.AddValue("ObjectName", ObjectName, typeof(string));
  82.         }
  83.        
  84.     }
  85. }

Developer Fusion