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

  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: ValueTypeFixupInfo
  18. **
  19. ** Purpose: Information about an object required to do a value-type
  20. ** fixup.  This includes the id of the containing object and the
  21. ** member info (if the containing body is an object or value type)
  22. ** or the array indices (if the containing body is an array.)
  23. **
  24. ============================================================*/
  25. namespace System.Runtime.Serialization
  26. {
  27.     using System.Reflection;
  28.    
  29.     internal class ValueTypeFixupInfo
  30.     {
  31.        
  32.         //The id of the containing body. This could be a regular
  33.         //object, another value type, or an array. For obvious reasons,
  34.         //the containing body can never have both a FieldInfo and
  35.         //an array index.
  36.         private long m_containerID;
  37.        
  38.         //The FieldInfo into the containing body. This will only
  39.         //apply if the containing body is a field info or another
  40.         //value type.
  41.         private FieldInfo m_parentField;
  42.        
  43.         //The array index of the index into the parent. This will only
  44.         //apply if the containing body is an array.
  45.         private int[] m_parentIndex;
  46.        
  47.         public ValueTypeFixupInfo(long containerID, FieldInfo member, int[] parentIndex)
  48.         {
  49.            
  50.             BCLDebug.Trace("SER", "[ValueTypeFixupInfo.ctor]Creating a VTFI with Container ID: ", containerID, " and MemberInfo ", member);
  51.            
  52.             if (containerID == 0 && member == null) {
  53.                 m_containerID = containerID;
  54.                 m_parentField = member;
  55.                 m_parentIndex = parentIndex;
  56.             }
  57.            
  58.             //If both member and arrayIndex are null, we don't have enough information to create
  59.             //a tunnel to do the fixup.
  60.             if (member == null && parentIndex == null) {
  61.                 throw new ArgumentException(Environment.GetResourceString("Argument_MustSupplyParent"));
  62.             }
  63.            
  64.             //If the member isn't null, we know that they supplied a MemberInfo as the parent. This means
  65.             //that the arrayIndex must be null because we can't have a FieldInfo into an array.
  66.             if (member != null) {
  67.                 if (parentIndex != null) {
  68.                     throw new ArgumentException(Environment.GetResourceString("Argument_MemberAndArray"));
  69.                 }
  70.                
  71.                 if (((((FieldInfo)member).FieldType).IsValueType) && containerID == 0) {
  72.                     throw new ArgumentException(Environment.GetResourceString("Argument_MustSupplyContainer"));
  73.                 }
  74.             }
  75.            
  76.             m_containerID = containerID;
  77.             m_parentField = (FieldInfo)member;
  78.             m_parentIndex = parentIndex;
  79.         }
  80.        
  81.         public long ContainerID {
  82.             get { return m_containerID; }
  83.         }
  84.        
  85.         public FieldInfo ParentField {
  86.             get { return m_parentField; }
  87.         }
  88.        
  89.         public int[] ParentIndex {
  90.             get { return m_parentIndex; }
  91.         }
  92.     }
  93. }

Developer Fusion