IKVM11  11
Java SE 11 Virtual Machine for .NET
Loading...
Searching...
No Matches
ParameterBuilder.cs
Go to the documentation of this file.
1/*
2 Copyright (C) 2008 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.Reflection.Metadata;
25
27{
28
29 internal sealed class ParameterBuilder
30 {
31
32 readonly MethodBuilder method;
33 short flags;
34 readonly short sequence;
35 readonly StringHandle nameIndex;
36 readonly string name;
37 int lazyPseudoToken;
38
46 internal ParameterBuilder(MethodBuilder method, int sequence, ParameterAttributes attribs, string name)
47 {
48 this.method = method;
49 this.flags = (short)attribs;
50 this.sequence = (short)sequence;
51 this.nameIndex = name == null ? default : method.ModuleBuilder.GetOrAddString(name);
52 this.name = name;
53 }
54
55 internal int PseudoToken
56 {
57 get
58 {
59 if (lazyPseudoToken == 0)
60 lazyPseudoToken = method.ModuleBuilder.AllocPseudoToken();
61
62 return lazyPseudoToken;
63 }
64 }
65
66 public MethodInfo Method => method;
67
68 public Module Module => method.Module;
69
70 public string Name
71 {
72 get { return name; }
73 }
74
78 public int Position
79 {
80 get { return sequence; }
81 }
82
83 public int Attributes
84 {
85 get { return flags; }
86 }
87
88 public bool IsIn
89 {
90 get { return (flags & (short)ParameterAttributes.In) != 0; }
91 }
92
93 public bool IsOut
94 {
95 get { return (flags & (short)ParameterAttributes.Out) != 0; }
96 }
97
98 public bool IsOptional
99 {
100 get { return (flags & (short)ParameterAttributes.Optional) != 0; }
101 }
102
103 public void SetCustomAttribute(ConstructorInfo con, byte[] binaryAttribute)
104 {
105 SetCustomAttribute(new CustomAttributeBuilder(con, binaryAttribute));
106 }
107
108 public void SetCustomAttribute(CustomAttributeBuilder customAttributeBuilder)
109 {
110 switch (customAttributeBuilder.KnownCA)
111 {
112 case KnownCA.InAttribute:
113 flags |= (short)ParameterAttributes.In;
114 break;
115 case KnownCA.OutAttribute:
116 flags |= (short)ParameterAttributes.Out;
117 break;
118 case KnownCA.OptionalAttribute:
119 flags |= (short)ParameterAttributes.Optional;
120 break;
121 case KnownCA.MarshalAsAttribute:
122 FieldMarshal.SetMarshalAsAttribute(method.ModuleBuilder, PseudoToken, customAttributeBuilder);
123 flags |= (short)ParameterAttributes.HasFieldMarshal;
124 break;
125 default:
126 method.ModuleBuilder.SetCustomAttribute(PseudoToken, customAttributeBuilder);
127 break;
128 }
129 }
130
131 public void SetConstant(object defaultValue)
132 {
133 flags |= (short)ParameterAttributes.HasDefault;
134 method.ModuleBuilder.AddConstant(PseudoToken, defaultValue);
135 }
136
137 internal void WriteMetadata()
138 {
139 method.ModuleBuilder.Metadata.AddParameter(
140 (System.Reflection.ParameterAttributes)flags,
141 nameIndex,
142 sequence);
143 }
144
145 internal void FixupToken(int parameterToken)
146 {
147 if (lazyPseudoToken != 0)
148 method.ModuleBuilder.RegisterTokenFixup(lazyPseudoToken, parameterToken);
149 }
150
151 }
152
153}
IKVM.Reflection.Module Module
IKVM.Reflection.ConstructorInfo ConstructorInfo
IKVM.Reflection.MethodInfo MethodInfo
global::java.lang.invoke.LambdaForm.Name Name
KnownCA
These are the pseudo-custom attributes that are recognized by name by the runtime (i....
Definition KnownCA.cs:35