e043c0f7f9101c5f54bfda72876f046b93aef033
[mono.git] / mcs / class / referencesource / mscorlib / system / reflection / emit / fieldtoken.cs
1 // ==++==
2 // 
3 //   Copyright (c) Microsoft Corporation.  All rights reserved.
4 // 
5 // ==--==
6 /*============================================================
7 **
8 ** Class:  FieldToken
9 ** 
10 ** <OWNER>Microsoft</OWNER>
11 **
12 **
13 ** Purpose: Represents a Field to the ILGenerator Class
14 **
15 ** 
16 ===========================================================*/
17 namespace System.Reflection.Emit {
18     
19     using System;
20     using System.Reflection;
21     using System.Security.Permissions;
22
23     // The FieldToken class is an opaque representation of the Token returned
24     // by the Metadata to represent the field.  FieldTokens are generated by 
25     // Module.GetFieldToken().  There are no meaningful accessors on this class,
26     // but it can be passed to ILGenerator which understands it's internals.
27     [Serializable]
28     [System.Runtime.InteropServices.ComVisible(true)]
29     public struct FieldToken
30     {
31         public static readonly FieldToken Empty = new FieldToken();
32
33         internal int m_fieldTok;
34         internal Object m_class;
35     
36         // Creates an empty FieldToken.  A publicly visible constructor so that
37         // it can be created on the stack.
38         //public FieldToken() {
39         //    m_fieldTok=0;
40         //    m_attributes=0;
41         //    m_class=null;
42         //}
43         // The actual constructor.  Sets the field, attributes and class
44         // variables
45     
46         internal FieldToken (int field, Type fieldClass) {
47             m_fieldTok=field;
48             m_class = fieldClass;
49         }
50         
51         public int Token {
52             get { return m_fieldTok; }
53         }
54         
55     
56         // Generates the hash code for this field. 
57         public override int GetHashCode()
58         {
59             return (m_fieldTok);
60         }
61     
62         // Returns true if obj is an instance of FieldToken and is 
63         // equal to this instance.
64         public override bool Equals(Object obj)
65         {
66             if (obj is FieldToken)
67                 return Equals((FieldToken)obj);
68             else
69                 return false;
70         }
71
72         public bool Equals(FieldToken obj)
73         {
74             return obj.m_fieldTok == m_fieldTok && obj.m_class == m_class;
75         }
76     
77         public static bool operator ==(FieldToken a, FieldToken b)
78         {
79             return a.Equals(b);
80         }
81         
82         public static bool operator !=(FieldToken a, FieldToken b)
83         {
84             return !(a == b);
85         }
86
87     }
88 }