The Labs \ Source Viewer \ SSCLI \ System.Text \ SurrogateEncoder

  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. // WARNING:
  16. //
  17. // This is just an IObjectReference proxy for the former V1.1 Surrogate Encoder
  18. // All this does is make an encoder of the correct type, it DOES NOT maintain state.
  19. namespace System.Text
  20. {
  21.     using System;
  22.     using System.Runtime.Serialization;
  23.     using System.Security.Permissions;
  24.    
  25. /*=================================SurrogateEncoder==================================
  26.     ** This class is here only to deserialize the SurrogateEncoder class from Everett (V1.1) into
  27.     ** Appropriate Whidbey (V2.0) objects.
  28.     ==============================================================================*/   
  29.    
  30.     [Serializable()]
  31.     internal sealed class SurrogateEncoder : ISerializable, IObjectReference
  32.     {
  33.         // Might need this when GetRealObjecting
  34.         [NonSerialized()]
  35.         private Encoding realEncoding = null;
  36.        
  37.         // Constructor called by serialization.
  38.         internal SurrogateEncoder(SerializationInfo info, StreamingContext context)
  39.         {
  40.             // Any info?
  41.             if (info == null)
  42.                 throw new ArgumentNullException("info");
  43.            
  44.             // All versions have a code page
  45.             this.realEncoding = (Encoding)info.GetValue("m_encoding", typeof(Encoding));
  46.         }
  47.        
  48.         // Just get it from GetEncoding
  49.         public object GetRealObject(StreamingContext context)
  50.         {
  51.             // Need to get our Encoding's Encoder
  52.             return this.realEncoding.GetEncoder();
  53.         }
  54.        
  55.         // ISerializable implementation
  56.         [SecurityPermissionAttribute(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.SerializationFormatter)]
  57.         void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
  58.         {
  59.             // We cannot ever call this.
  60.             BCLDebug.Assert(false, "Didn't expect to make it to SurrogateEncoder.GetObjectData");
  61.             throw new ArgumentException(Environment.GetResourceString("Arg_ExecutionEngineException"));
  62.         }
  63.     }
  64. }

Developer Fusion