The Labs \ Source Viewer \ SSCLI \ System.Reflection.Emit \ FieldToken

  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:  FieldToken
  18. **
  19. **
  20. ** Purpose: Represents a Field to the ILGenerator Class
  21. **
  22. **
  23. ===========================================================*/
  24. namespace System.Reflection.Emit
  25. {
  26.    
  27.     using System;
  28.     using System.Reflection;
  29.     using System.Security.Permissions;
  30.    
  31.     // The FieldToken class is an opaque representation of the Token returned
  32.     // by the Metadata to represent the field. FieldTokens are generated by
  33.     // Module.GetFieldToken(). There are no meaningful accessors on this class,
  34.     // but it can be passed to ILGenerator which understands it's internals.
  35.     [Serializable()]
  36.     [System.Runtime.InteropServices.ComVisible(true)]
  37.     public struct FieldToken
  38.     {
  39.         public static readonly FieldToken Empty = new FieldToken();
  40.        
  41.         internal int m_fieldTok;
  42.         internal object m_class;
  43.        
  44.         // Creates an empty FieldToken. A publicly visible constructor so that
  45.         // it can be created on the stack.
  46.         //public FieldToken() {
  47.         // m_fieldTok=0;
  48.         // m_attributes=0;
  49.         // m_class=null;
  50.         //}
  51.         // The actual constructor. Sets the field, attributes and class
  52.         // variables
  53.        
  54.         internal FieldToken(int field, Type fieldClass)
  55.         {
  56.             m_fieldTok = field;
  57.             m_class = fieldClass;
  58.         }
  59.        
  60.         public int Token {
  61.             get { return m_fieldTok; }
  62.         }
  63.        
  64.        
  65.         // Generates the hash code for this field.
  66.         public override int GetHashCode()
  67.         {
  68.             return (m_fieldTok);
  69.         }
  70.        
  71.         // Returns true if obj is an instance of FieldToken and is
  72.         // equal to this instance.
  73.         public override bool Equals(object obj)
  74.         {
  75.             if (obj is FieldToken)
  76.                 return Equals((FieldToken)obj);
  77.             else
  78.                 return false;
  79.         }
  80.        
  81.         public bool Equals(FieldToken obj)
  82.         {
  83.             return obj.m_fieldTok == m_fieldTok && obj.m_class == m_class;
  84.         }
  85.        
  86.         public static bool operator ==(FieldToken a, FieldToken b)
  87.         {
  88.             return a.Equals(b);
  89.         }
  90.        
  91.         public static bool operator !=(FieldToken a, FieldToken b)
  92.         {
  93.             return !(a == b);
  94.         }
  95.        
  96.     }
  97. }

Developer Fusion