Update mcs/class/System.Core/System/TimeZoneInfo.cs
[mono.git] / mcs / class / IKVM.Reflection / FieldSignature.cs
1 /*
2   Copyright (C) 2009 Jeroen Frijters
3
4   This software is provided 'as-is', without any express or implied
5   warranty.  In no event will the authors be held liable for any damages
6   arising from the use of this software.
7
8   Permission is granted to anyone to use this software for any purpose,
9   including commercial applications, and to alter it and redistribute it
10   freely, subject to the following restrictions:
11
12   1. The origin of this software must not be misrepresented; you must not
13      claim that you wrote the original software. If you use this software
14      in a product, an acknowledgment in the product documentation would be
15      appreciated but is not required.
16   2. Altered source versions must be plainly marked as such, and must not be
17      misrepresented as being the original software.
18   3. This notice may not be removed or altered from any source distribution.
19
20   Jeroen Frijters
21   jeroen@frijters.net
22   
23 */
24 using System;
25 using System.Collections.Generic;
26 using System.IO;
27 using System.Text;
28 using IKVM.Reflection.Emit;
29 using IKVM.Reflection.Writer;
30 using IKVM.Reflection.Reader;
31
32 namespace IKVM.Reflection
33 {
34         sealed class FieldSignature : Signature
35         {
36                 private readonly Type fieldType;
37                 private readonly CustomModifiers mods;
38
39                 internal static FieldSignature Create(Type fieldType, CustomModifiers customModifiers)
40                 {
41                         return new FieldSignature(fieldType, customModifiers);
42                 }
43
44                 private FieldSignature(Type fieldType, CustomModifiers mods)
45                 {
46                         this.fieldType = fieldType;
47                         this.mods = mods;
48                 }
49
50                 public override bool Equals(object obj)
51                 {
52                         FieldSignature other = obj as FieldSignature;
53                         return other != null
54                                 && other.fieldType.Equals(fieldType)
55                                 && other.mods.Equals(mods);
56                 }
57
58                 public override int GetHashCode()
59                 {
60                         return fieldType.GetHashCode() ^ mods.GetHashCode();
61                 }
62
63                 internal Type FieldType
64                 {
65                         get { return fieldType; }
66                 }
67
68                 internal CustomModifiers GetCustomModifiers()
69                 {
70                         return mods;
71                 }
72
73                 internal FieldSignature ExpandTypeParameters(Type declaringType)
74                 {
75                         return new FieldSignature(
76                                 fieldType.BindTypeParameters(declaringType),
77                                 mods.Bind(declaringType));
78                 }
79
80                 internal static FieldSignature ReadSig(ModuleReader module, ByteReader br, IGenericContext context)
81                 {
82                         if (br.ReadByte() != FIELD)
83                         {
84                                 throw new BadImageFormatException();
85                         }
86                         CustomModifiers mods = CustomModifiers.Read(module, br, context);
87                         Type fieldType = ReadType(module, br, context);
88                         return new FieldSignature(fieldType, mods);
89                 }
90
91                 internal override void WriteSig(ModuleBuilder module, ByteBuffer bb)
92                 {
93                         bb.Write(FIELD);
94                         WriteCustomModifiers(module, bb, mods);
95                         WriteType(module, bb, fieldType);
96                 }
97         }
98 }