IKVM11  11
Java SE 11 Virtual Machine for .NET
Loading...
Searching...
No Matches
ParameterInfoImpl.cs
Go to the documentation of this file.
1/*
2 Copyright (C) 2009-2012 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*/
24using System;
25using System.Collections.Generic;
26
28
30{
31
32 sealed class ParameterInfoImpl : ParameterInfo
33 {
34
35 readonly MethodDefImpl method;
36 readonly int position;
37 readonly int index;
38
45 internal ParameterInfoImpl(MethodDefImpl method, int position, int index)
46 {
47 this.method = method;
48 this.position = position;
49 this.index = index;
50 }
51
52 public override string Name
53 {
54 get { return index == -1 ? null : ((ModuleReader)this.Module).GetString(this.Module.ParamTable.records[index].Name); }
55 }
56
57 public override Type ParameterType
58 {
59 get { return position == -1 ? method.MethodSignature.GetReturnType(method) : method.MethodSignature.GetParameterType(method, position); }
60 }
61
62 public override ParameterAttributes Attributes
63 {
64 get { return index == -1 ? ParameterAttributes.None : (ParameterAttributes)this.Module.ParamTable.records[index].Flags; }
65 }
66
67 public override int Position
68 {
69 get { return position; }
70 }
71
72 public override object RawDefaultValue
73 {
74 get
75 {
76 if ((Attributes & ParameterAttributes.HasDefault) != 0)
77 return Module.ConstantTable.GetRawConstantValue(Module, MetadataToken);
78
79 var universe = Module.Universe;
80 if (ParameterType == universe.System_Decimal)
81 {
82 var attr = universe.System_Runtime_CompilerServices_DecimalConstantAttribute;
83 if (attr != null)
84 {
85 foreach (var cad in CustomAttributeData.__GetCustomAttributes(this, attr, false))
86 {
87 var args = cad.ConstructorArguments;
88 if (args.Count == 5)
89 {
90 if (args[0].ArgumentType == universe.System_Byte &&
91 args[1].ArgumentType == universe.System_Byte &&
92 args[2].ArgumentType == universe.System_Int32 &&
93 args[3].ArgumentType == universe.System_Int32 &&
94 args[4].ArgumentType == universe.System_Int32)
95 {
96 return new decimal((int)args[4].Value, (int)args[3].Value, (int)args[2].Value, (byte)args[1].Value != 0, (byte)args[0].Value);
97 }
98 else if (args[0].ArgumentType == universe.System_Byte &&
99 args[1].ArgumentType == universe.System_Byte &&
100 args[2].ArgumentType == universe.System_UInt32 &&
101 args[3].ArgumentType == universe.System_UInt32 &&
102 args[4].ArgumentType == universe.System_UInt32)
103 {
104 return new Decimal(unchecked((int)(uint)args[4].Value), unchecked((int)(uint)args[3].Value), unchecked((int)(uint)args[2].Value), (byte)args[1].Value != 0, (byte)args[0].Value);
105 }
106 }
107 }
108 }
109 }
110
111 if ((Attributes & ParameterAttributes.Optional) != 0)
112 return Missing.Value;
113
114 return null;
115 }
116 }
117
118 public override CustomModifiers __GetCustomModifiers()
119 {
120 return position == -1 ? method.MethodSignature.GetReturnTypeCustomModifiers(method) : method.MethodSignature.GetParameterCustomModifiers(method, position);
121 }
122
123 public override bool __TryGetFieldMarshal(out FieldMarshal fieldMarshal)
124 {
125 return FieldMarshal.ReadFieldMarshal(this.Module, this.MetadataToken, out fieldMarshal);
126 }
127
128 public override MemberInfo Member
129 {
130 get
131 {
132 // return the right ConstructorInfo wrapper
133 return method.Module.ResolveMethod(method.MetadataToken);
134 }
135 }
136
137 public override int MetadataToken
138 {
139 get
140 {
141 // for parameters that don't have a row in the Param table, we return 0x08000000 (because index is -1 in that case),
142 // just like .NET
143 return (ParamTable.Index << 24) + index + 1;
144 }
145 }
146
147 public override Module Module
148 {
149 get { return method.Module; }
150 }
151
152 }
153
154}
global::java.lang.invoke.LambdaForm.Name Name
override bool __TryGetFieldMarshal(out FieldMarshal fieldMarshal)
override ParameterAttributes Attributes
override CustomModifiers __GetCustomModifiers()