~ubuntu-branches/ubuntu/oneiric/monodevelop/oneiric

« back to all changes in this revision

Viewing changes to contrib/Mono.Cecil/Mono.Cecil/Mono.Cecil.Metadata/MetadataToken.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2011-06-27 17:03:13 UTC
  • mto: (1.8.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 54.
  • Revision ID: james.westby@ubuntu.com-20110627170313-6cvz3s19x6e9hqe9
ImportĀ upstreamĀ versionĀ 2.5.92+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
// Author:
5
5
//   Jb Evain (jbevain@gmail.com)
6
6
//
7
 
// (C) 2005 Jb Evain
 
7
// Copyright (c) 2008 - 2010 Jb Evain
8
8
//
9
9
// Permission is hereby granted, free of charge, to any person obtaining
10
10
// a copy of this software and associated documentation files (the
26
26
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27
27
//
28
28
 
29
 
namespace Mono.Cecil.Metadata {
 
29
namespace Mono.Cecil {
30
30
 
31
31
        public struct MetadataToken {
32
32
 
33
 
                uint m_rid;
34
 
                TokenType m_type;
 
33
                readonly uint token;
35
34
 
36
 
                public uint RID {
37
 
                        get { return m_rid; }
 
35
                public uint RID {
 
36
                        get { return token & 0x00ffffff; }
38
37
                }
39
38
 
40
39
                public TokenType TokenType {
41
 
                        get { return m_type; }
42
 
                }
43
 
 
44
 
                public static readonly MetadataToken Zero = new MetadataToken ((TokenType) 0, 0);
45
 
 
46
 
                public MetadataToken (int token)
47
 
                {
48
 
                        m_type = (TokenType) (token & 0xff000000);
49
 
                        m_rid = (uint) token & 0x00ffffff;
50
 
                }
51
 
 
52
 
                public MetadataToken (TokenType table, uint rid)
53
 
                {
54
 
                        m_type = table;
55
 
                        m_rid = rid;
56
 
                }
57
 
 
58
 
                internal static MetadataToken FromMetadataRow (TokenType table, int rowIndex)
59
 
                {
60
 
                        return new MetadataToken (table, (uint) rowIndex + 1);
61
 
                }
62
 
 
63
 
                public uint ToUInt ()
64
 
                {
65
 
                        return (uint) m_type | m_rid;
 
40
                        get { return (TokenType) (token & 0xff000000); }
 
41
                }
 
42
 
 
43
                public static readonly MetadataToken Zero = new MetadataToken ((uint) 0);
 
44
 
 
45
                public MetadataToken (uint token)
 
46
                {
 
47
                        this.token = token;
 
48
                }
 
49
 
 
50
                public MetadataToken (TokenType type)
 
51
                        : this (type, 0)
 
52
                {
 
53
                }
 
54
 
 
55
                public MetadataToken (TokenType type, uint rid)
 
56
                {
 
57
                        token = (uint) type | rid;
 
58
                }
 
59
 
 
60
                public MetadataToken (TokenType type, int rid)
 
61
                {
 
62
                        token = (uint) type | (uint) rid;
 
63
                }
 
64
 
 
65
                public int ToInt32 ()
 
66
                {
 
67
                        return (int) token;
 
68
                }
 
69
 
 
70
                public uint ToUInt32 ()
 
71
                {
 
72
                        return token;
66
73
                }
67
74
 
68
75
                public override int GetHashCode ()
69
76
                {
70
 
                        return (int) ToUInt ();
 
77
                        return (int) token;
71
78
                }
72
79
 
73
 
                public override bool Equals (object other)
 
80
                public override bool Equals (object obj)
74
81
                {
75
 
                        if (other is MetadataToken)
76
 
                                return Equals ((MetadataToken) other);
 
82
                        if (obj is MetadataToken) {
 
83
                                var other = (MetadataToken) obj;
 
84
                                return other.token == token;
 
85
                        }
77
86
 
78
87
                        return false;
79
88
                }
80
89
 
81
 
                private bool Equals (MetadataToken other)
82
 
                {
83
 
                        return other.m_rid == m_rid && other.m_type == m_type;
84
 
                }
85
 
 
86
90
                public static bool operator == (MetadataToken one, MetadataToken other)
87
91
                {
88
 
                        return one.Equals (other);
 
92
                        return one.token == other.token;
89
93
                }
90
94
 
91
95
                public static bool operator != (MetadataToken one, MetadataToken other)
92
96
                {
93
 
                        return !one.Equals (other);
 
97
                        return one.token != other.token;
94
98
                }
95
99
 
96
100
                public override string ToString ()
97
101
                {
98
 
                        return string.Format ("{0} [0x{1}]",
99
 
                                m_type, m_rid.ToString ("x4"));
 
102
                        return string.Format ("[{0}:0x{1}]", TokenType, RID.ToString ("x4"));
100
103
                }
101
104
        }
102
105
}