1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
//! Owned `GenericParam` structures for the `GenericParam` metadata table.
//!
//! This module provides the [`GenericParam`] struct which represents generic parameter
//! definitions with resolved references and owned data. Generic parameters enable
//! type-safe generic programming in .NET assemblies.
//!
//! # Purpose
//! The `GenericParam` table enables generic programming support:
//! - **Generic types**: Type parameters for classes and interfaces (`List<T>`)
//! - **Generic methods**: Method-level type parameters (`Method<U>()`)
//! - **Constraint specification**: Base class and interface constraints
//! - **Variance annotations**: Covariance and contravariance for type safety
//! - **Reflection metadata**: Runtime access to generic parameter information
//!
//! # Generic Parameter Context
//! Generic parameters provide type parameterization:
//! - **Type abstraction**: Define types that work with multiple concrete types
//! - **Type safety**: Compile-time verification of generic type usage
//! - **Performance**: Avoid boxing/unboxing with value types
//! - **Code reuse**: Single implementation works with many types
//! - **Constraint enforcement**: Compile-time constraint checking
//!
//! # ECMA-335 Reference
//! See ECMA-335, Partition II, §22.20 for the `GenericParam` table specification.
use ;
use crate::;
/// Represents a generic parameter definition with resolved references and owned data.
///
/// A generic parameter defines a type or method parameter that can be substituted with
/// concrete types during instantiation. This enables generic programming with type safety
/// and performance benefits.
///
/// # Generic Parameter Types
/// Parameters can be defined at different scopes:
/// - **Type parameters**: Defined on classes, interfaces, and delegates
/// - **Method parameters**: Defined on individual methods
/// - **Nested parameters**: Parameters within generic types can have their own parameters
///
/// # Parameter Characteristics
/// Each parameter has several important properties:
/// - **Position**: Ordinal position in the parameter list (0-based)
/// - **Name**: Identifier used in signatures and source code
/// - **Constraints**: Restrictions on acceptable type arguments
/// - **Variance**: Covariance/contravariance for assignment compatibility
/// - **Owner**: The type or method that declares the parameter
///
/// # Variance Support
/// Generic parameters can specify variance for type safety:
/// ```text
/// ┌──────────────┬─────────────────┬─────────────────────────────┐
/// │ Variance │ Keyword │ Assignment Compatibility │
/// ├──────────────┼─────────────────┼─────────────────────────────┤
/// │ Invariant │ (none) │ Exact type match required │
/// │ Covariant │ out │ Derived → Base allowed │
/// │ Contravariant│ in │ Base → Derived allowed │
/// └──────────────┴─────────────────┴─────────────────────────────┘
/// ```
///
/// # Constraint Types
/// Parameters can have various constraints:
/// - **Class constraint**: `where T : class` (reference types only)
/// - **Struct constraint**: `where T : struct` (value types only)
/// - **Constructor constraint**: `where T : new()` (parameterless constructor)
/// - **Base class constraint**: `where T : BaseClass` (inheritance requirement)
/// - **Interface constraints**: `where T : IInterface` (implementation requirement)
///
/// # Owner Resolution
/// Generic parameters are owned by either types or methods:
/// - **Type ownership**: Parameters declared on generic types
/// - **Method ownership**: Parameters declared on generic methods
/// - **Lazy resolution**: Owner is resolved when first accessed
/// - **Type reference**: Uses `CilTypeReference` for unified handling
///
/// # ECMA-335 Reference
/// See ECMA-335, Partition II, §22.20 for the complete `GenericParam` table specification.