The Labs \ Source Viewer \ SSCLI \ System.Runtime.Serialization \ SerializationFieldInfo

  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. /*============================================================
  16. **
  17. ** Class: SerializationFieldInfo
  18. **
  19. **
  20. ** Purpose: Provides a methods of representing imaginary fields
  21. ** which are unique to serialization.  In this case, what we're
  22. ** representing is the private members of parent classes.  We
  23. ** aggregate the RuntimeFieldInfo associated with this member
  24. ** and return a managled form of the name.  The name that we
  25. ** return is .parentname.fieldname
  26. **
  27. **
  28. ============================================================*/
  29. using System;
  30. using System.Reflection;
  31. using System.Globalization;
  32. namespace System.Runtime.Serialization
  33. {
  34.    
  35.     internal sealed class SerializationFieldInfo : FieldInfo
  36.     {
  37.        
  38.         static internal readonly char FakeNameSeparatorChar = '+';
  39.         static internal readonly string FakeNameSeparatorString = "+";
  40.        
  41.         private RuntimeFieldInfo m_field;
  42.         private string m_serializationName;
  43.        
  44.         public override Module Module {
  45.             get { return m_field.Module; }
  46.         }
  47.         public override int MetadataToken {
  48.             get { return m_field.MetadataToken; }
  49.         }
  50.        
  51.         internal SerializationFieldInfo(RuntimeFieldInfo field, string namePrefix)
  52.         {
  53.             BCLDebug.Assert(field != null, "[SerializationFieldInfo.ctor]field!=null");
  54.             BCLDebug.Assert(namePrefix != null, "[SerializationFieldInfo.ctor]namePrefix!=null");
  55.            
  56.             m_field = field;
  57.             m_serializationName = String.Concat(namePrefix, FakeNameSeparatorString, m_field.Name);
  58.         }
  59.        
  60.         //
  61.         // MemberInfo methods
  62.         //
  63.         public override string Name {
  64.             get { return m_serializationName; }
  65.         }
  66.        
  67.         public override Type DeclaringType {
  68.             get { return m_field.DeclaringType; }
  69.         }
  70.        
  71.         public override Type ReflectedType {
  72.             get { return m_field.ReflectedType; }
  73.         }
  74.        
  75.         public override object[] GetCustomAttributes(bool inherit)
  76.         {
  77.             return m_field.GetCustomAttributes(inherit);
  78.         }
  79.        
  80.         public override object[] GetCustomAttributes(Type attributeType, bool inherit)
  81.         {
  82.             return m_field.GetCustomAttributes(attributeType, inherit);
  83.         }
  84.        
  85.         public override bool IsDefined(Type attributeType, bool inherit)
  86.         {
  87.             return m_field.IsDefined(attributeType, inherit);
  88.         }
  89.        
  90.         //
  91.         // FieldInfo methods
  92.         //
  93.         public override Type FieldType {
  94.             get { return m_field.FieldType; }
  95.         }
  96.        
  97.         public override object GetValue(object obj)
  98.         {
  99.             return m_field.GetValue(obj);
  100.         }
  101.        
  102.         internal object InternalGetValue(object obj, bool requiresAccessCheck)
  103.         {
  104.             RtFieldInfo field = m_field as RtFieldInfo;
  105.             if (field != null)
  106.                 return field.InternalGetValue(obj, requiresAccessCheck);
  107.             else
  108.                 return m_field.GetValue(obj);
  109.         }
  110.        
  111.         public override void SetValue(object obj, object value, BindingFlags invokeAttr, Binder binder, CultureInfo culture)
  112.         {
  113.             m_field.SetValue(obj, value, invokeAttr, binder, culture);
  114.         }
  115.        
  116.         internal void InternalSetValue(object obj, object value, BindingFlags invokeAttr, Binder binder, CultureInfo culture, bool requiresAccessCheck, bool isBinderDefault)
  117.         {
  118.             //m_field.InternalSetValue(obj, value, invokeAttr, binder, culture, requiresAccessCheck, isBinderDefault);
  119.             RtFieldInfo field = m_field as RtFieldInfo;
  120.             if (field != null)
  121.                 field.InternalSetValue(obj, value, invokeAttr, binder, culture, false);
  122.             else
  123.                 m_field.SetValue(obj, value, invokeAttr, binder, culture);
  124.         }
  125.        
  126.         internal RuntimeFieldInfo FieldInfo {
  127.             get { return m_field; }
  128.         }
  129.        
  130.         public override RuntimeFieldHandle FieldHandle {
  131.             get { return m_field.FieldHandle; }
  132.         }
  133.        
  134.         public override FieldAttributes Attributes {
  135.             get { return m_field.Attributes; }
  136.         }
  137.        
  138.     }
  139. }

Developer Fusion