IKVM11  11
Java SE 11 Virtual Machine for .NET
Loading...
Searching...
No Matches
PropertySignature.cs
Go to the documentation of this file.
1/*
2 Copyright (C) 2009-2011 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*/
27
28namespace IKVM.Reflection
29{
30
32 {
33
34 CallingConventions callingConvention;
35 readonly Type propertyType;
36 readonly Type[] parameterTypes;
37 readonly PackedCustomModifiers customModifiers;
38
39 internal static PropertySignature Create(CallingConventions callingConvention, Type propertyType, Type[] parameterTypes, PackedCustomModifiers customModifiers)
40 {
41 return new PropertySignature(callingConvention, propertyType, Util.Copy(parameterTypes), customModifiers);
42 }
43
51 PropertySignature(CallingConventions callingConvention, Type propertyType, Type[] parameterTypes, PackedCustomModifiers customModifiers)
52 {
53 this.callingConvention = callingConvention;
54 this.propertyType = propertyType;
55 this.parameterTypes = parameterTypes;
56 this.customModifiers = customModifiers;
57 }
58
59 public override bool Equals(object obj)
60 {
61 var other = obj as PropertySignature;
62 return other != null
63 && other.propertyType.Equals(propertyType)
64 && other.customModifiers.Equals(customModifiers);
65 }
66
67 public override int GetHashCode()
68 {
69 return propertyType.GetHashCode() ^ customModifiers.GetHashCode();
70 }
71
72 internal int ParameterCount
73 {
74 get { return parameterTypes.Length; }
75 }
76
77 internal bool HasThis
78 {
79 set
80 {
81 if (value)
82 callingConvention |= CallingConventions.HasThis;
83 else
84 callingConvention &= ~CallingConventions.HasThis;
85 }
86 }
87
88 internal Type PropertyType
89 {
90 get { return propertyType; }
91 }
92
93 internal CustomModifiers GetCustomModifiers()
94 {
95 return customModifiers.GetReturnTypeCustomModifiers();
96 }
97
98 internal PropertySignature ExpandTypeParameters(Type declaringType)
99 {
100 return new PropertySignature(callingConvention, propertyType.BindTypeParameters(declaringType), BindTypeParameters(declaringType, parameterTypes), customModifiers.Bind(declaringType));
101 }
102
103 internal override void Write(ModuleBuilder module, ByteBuffer bb)
104 {
105 var flags = PROPERTY;
106 if ((callingConvention & CallingConventions.HasThis) != 0)
107 flags |= HASTHIS;
108 if ((callingConvention & CallingConventions.ExplicitThis) != 0)
109 flags |= EXPLICITTHIS;
110 if ((callingConvention & CallingConventions.VarArgs) != 0)
111 flags |= VARARG;
112
113 bb.Write(flags);
114 bb.WriteCompressedUInt(parameterTypes == null ? 0 : parameterTypes.Length);
115 WriteCustomModifiers(module, bb, customModifiers.GetReturnTypeCustomModifiers());
116 WriteType(module, bb, propertyType);
117
118 if (parameterTypes != null)
119 {
120 for (var i = 0; i < parameterTypes.Length; i++)
121 {
122 WriteCustomModifiers(module, bb, customModifiers.GetParameterCustomModifiers(i));
123 WriteType(module, bb, parameterTypes[i]);
124 }
125 }
126 }
127
128 internal Type GetParameter(int parameter)
129 {
130 return parameterTypes[parameter];
131 }
132
133 internal CustomModifiers GetParameterCustomModifiers(int parameter)
134 {
135 return customModifiers.GetParameterCustomModifiers(parameter);
136 }
137
138 internal CallingConventions CallingConvention
139 {
140 get { return callingConvention; }
141 }
142
143 internal bool MatchParameterTypes(Type[] types)
144 {
145 return Util.ArrayEquals(types, parameterTypes);
146 }
147
148 internal static PropertySignature ReadSig(ModuleReader module, ByteReader br, IGenericContext context)
149 {
150 var flags = br.ReadByte();
151 if ((flags & PROPERTY) == 0)
152 throw new BadImageFormatException();
153
154 var callingConvention = CallingConventions.Standard;
155 if ((flags & HASTHIS) != 0)
156 callingConvention |= CallingConventions.HasThis;
157 if ((flags & EXPLICITTHIS) != 0)
158 callingConvention |= CallingConventions.ExplicitThis;
159
160 int paramCount = br.ReadCompressedUInt();
161 CustomModifiers[] mods = null;
162 PackedCustomModifiers.Pack(ref mods, 0, CustomModifiers.Read(module, br, context), paramCount + 1);
163 var returnType = ReadRetType(module, br, context);
164 var parameterTypes = new Type[paramCount];
165 for (int i = 0; i < parameterTypes.Length; i++)
166 {
167 PackedCustomModifiers.Pack(ref mods, i + 1, CustomModifiers.Read(module, br, context), paramCount + 1);
168 parameterTypes[i] = ReadParam(module, br, context);
169 }
170
171 return new PropertySignature(callingConvention, returnType, parameterTypes, PackedCustomModifiers.Wrap(mods));
172 }
173 }
174}
IKVM.Reflection.Type Type
System.Runtime.InteropServices.CallingConvention CallingConvention
Definition Signature.cs:35
override bool Equals(object obj)
static void WriteCustomModifiers(ModuleBuilder module, ByteBuffer bb, CustomModifiers modifiers)
Definition Signature.cs:419
static void WriteType(ModuleBuilder module, ByteBuffer bb, Type type)
Definition Signature.cs:339
static Type[] BindTypeParameters(IGenericBinder binder, Type[] types)
Definition Signature.cs:546
static Type ReadParam(ModuleReader module, ByteReader br, IGenericContext context)
Definition Signature.cs:327
static Type ReadRetType(ModuleReader module, ByteReader br, IGenericContext context)
Definition Signature.cs:312