IKVM11  11
Java SE 11 Virtual Machine for .NET
Loading...
Searching...
No Matches
PackedCustomModifiers.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*/
24namespace IKVM.Reflection
25{
26
27 readonly struct PackedCustomModifiers
28 {
29
30 // element 0 is the return type, the rest are the parameters
31 readonly CustomModifiers[] customModifiers;
32
37 private PackedCustomModifiers(CustomModifiers[] customModifiers)
38 {
39 this.customModifiers = customModifiers;
40 }
41
42 public override int GetHashCode()
43 {
44 return Util.GetHashCode(customModifiers);
45 }
46
47 public override bool Equals(object obj)
48 {
49 var other = obj as PackedCustomModifiers?;
50 return other != null && Equals(other.Value);
51 }
52
53 internal bool Equals(PackedCustomModifiers other)
54 {
55 return Util.ArrayEquals(customModifiers, other.customModifiers);
56 }
57
58 internal CustomModifiers GetReturnTypeCustomModifiers()
59 {
60 if (customModifiers == null)
61 return new CustomModifiers();
62
63 return customModifiers[0];
64 }
65
66 internal CustomModifiers GetParameterCustomModifiers(int index)
67 {
68 if (customModifiers == null)
69 return new CustomModifiers();
70
71 return customModifiers[index + 1];
72 }
73
74 internal PackedCustomModifiers Bind(IGenericBinder binder)
75 {
76 if (customModifiers == null)
77 return new PackedCustomModifiers();
78
79 var expanded = new CustomModifiers[customModifiers.Length];
80 for (int i = 0; i < customModifiers.Length; i++)
81 expanded[i] = customModifiers[i].Bind(binder);
82
83 return new PackedCustomModifiers(expanded);
84 }
85
86 internal bool ContainsMissingType
87 {
88 get
89 {
90 if (customModifiers != null)
91 for (int i = 0; i < customModifiers.Length; i++)
92 if (customModifiers[i].ContainsMissingType)
93 return true;
94
95 return false;
96 }
97 }
98
99 // this method make a copy of the incoming arrays (where necessary) and returns a normalized modifiers array
100 internal static PackedCustomModifiers CreateFromExternal(Type[] returnOptional, Type[] returnRequired, Type[][] parameterOptional, Type[][] parameterRequired, int parameterCount)
101 {
102 CustomModifiers[] modifiers = null;
103
104 Pack(ref modifiers, 0, CustomModifiers.FromReqOpt(returnRequired, returnOptional), parameterCount + 1);
105 for (int i = 0; i < parameterCount; i++)
106 Pack(ref modifiers, i + 1, CustomModifiers.FromReqOpt(Util.NullSafeElementAt(parameterRequired, i), Util.NullSafeElementAt(parameterOptional, i)), parameterCount + 1);
107
108 return new PackedCustomModifiers(modifiers);
109 }
110
111 internal static PackedCustomModifiers CreateFromExternal(CustomModifiers returnTypeCustomModifiers, CustomModifiers[] parameterTypeCustomModifiers, int parameterCount)
112 {
113 CustomModifiers[] customModifiers = null;
114
115 Pack(ref customModifiers, 0, returnTypeCustomModifiers, parameterCount + 1);
116 if (parameterTypeCustomModifiers != null)
117 for (int i = 0; i < parameterCount; i++)
118 Pack(ref customModifiers, i + 1, parameterTypeCustomModifiers[i], parameterCount + 1);
119
120 return new PackedCustomModifiers(customModifiers);
121 }
122
123 internal static PackedCustomModifiers Wrap(CustomModifiers[] modifiers)
124 {
125 return new PackedCustomModifiers(modifiers);
126 }
127
128 internal static void Pack(ref CustomModifiers[] array, int index, CustomModifiers mods, int count)
129 {
130 if (!mods.IsEmpty)
131 {
132 array ??= new CustomModifiers[count];
133 array[index] = mods;
134 }
135 }
136
137 }
138
139}
IKVM.Reflection.Type Type