summaryrefslogtreecommitdiff
path: root/src/mscorlib/src/System/Reflection/Emit/FieldToken.cs
blob: add428f96e927cb3ab9083c15c1479e4524dfa89 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

/*============================================================
**
** 
** 
**
**
** Purpose: Represents a Field to the ILGenerator Class
**
** 
===========================================================*/
namespace System.Reflection.Emit {
    
    using System;
    using System.Reflection;

    // The FieldToken class is an opaque representation of the Token returned
    // by the Metadata to represent the field.  FieldTokens are generated by 
    // Module.GetFieldToken().  There are no meaningful accessors on this class,
    // but it can be passed to ILGenerator which understands it's internals.
    [Serializable]
    public struct FieldToken
    {
        public static readonly FieldToken Empty = new FieldToken();

        internal int m_fieldTok;
        internal Object m_class;
    
        // Creates an empty FieldToken.  A publicly visible constructor so that
        // it can be created on the stack.
        //public FieldToken() {
        //    m_fieldTok=0;
        //    m_attributes=0;
        //    m_class=null;
        //}
        // The actual constructor.  Sets the field, attributes and class
        // variables
    
        internal FieldToken (int field, Type fieldClass) {
            m_fieldTok=field;
            m_class = fieldClass;
        }
        
        public int Token {
            get { return m_fieldTok; }
        }
        
    
        // Generates the hash code for this field. 
        public override int GetHashCode()
        {
            return (m_fieldTok);
        }
    
        // Returns true if obj is an instance of FieldToken and is 
        // equal to this instance.
        public override bool Equals(Object obj)
        {
            if (obj is FieldToken)
                return Equals((FieldToken)obj);
            else
                return false;
        }

        public bool Equals(FieldToken obj)
        {
            return obj.m_fieldTok == m_fieldTok && obj.m_class == m_class;
        }
    
        public static bool operator ==(FieldToken a, FieldToken b)
        {
            return a.Equals(b);
        }
        
        public static bool operator !=(FieldToken a, FieldToken b)
        {
            return !(a == b);
        }

    }
}