Skip to content

Commit c112874

Browse files
committed
Make ParameterData properties public for external access
Converted internal properties and methods in ParameterData to public, enabling external access to parameter metadata (type handles, position, default value, attributes, member data, etc.). Removed GetParameterInfo() in favor of direct property access. Updated ParameterList and WellKnownParameterDescriptor to use the new public ParameterInfo property. Internal helper methods are now private. This improves visibility and usability of parameter metadata across the codebase.
1 parent 5849180 commit c112874

3 files changed

Lines changed: 57 additions & 93 deletions

File tree

‎src/BionicCode.Utilities.Reflection/ParameterData.cs‎

Lines changed: 54 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -52,44 +52,41 @@ internal ParameterData(SymbolReflectionInfoCacheKey symbolInfoDataCacheKey)
5252
ParameterInfo = symbolInfoDataCacheKey.ParameterDescriptor.ParameterInfo;
5353
}
5454

55-
internal ParameterInfo GetParameterInfo()
56-
=> ParameterInfo;
57-
58-
internal Type GetDeclaringType()
55+
public Type GetDeclaringType()
5956
=> Type.GetTypeFromHandle(DeclaringTypeHandle)!;
6057

61-
internal RuntimeTypeHandle DeclaringTypeHandle
62-
=> _declaringTypeHandle ??= GetParameterInfo().Member.DeclaringType?.TypeHandle ?? throw new NotSupportedException($"The underlying '{typeof(ParameterInfo).FullName}' belongs to a member that does not return a declaring type.");
58+
public RuntimeTypeHandle DeclaringTypeHandle
59+
=> _declaringTypeHandle ??= ParameterInfo.Member.DeclaringType?.TypeHandle ?? throw new NotSupportedException($"The underlying '{typeof(ParameterInfo).FullName}' belongs to a member that does not return a declaring type.");
6360

64-
internal RuntimeTypeHandle ParameterTypeHandle
65-
=> _propertyTypeHandle ??= GetParameterInfo().ParameterType.TypeHandle;
61+
public RuntimeTypeHandle ParameterTypeHandle
62+
=> _propertyTypeHandle ??= ParameterInfo.ParameterType.TypeHandle;
6663

6764
/// <summary>
6865
/// Gets a value indicating whether the current type is passed by reference using the <see langword="ref"/> keyword.
6966
/// </summary>
7067
/// <value><see langword="true"/> if the parameter is passed by reference using the <c>ref</c> keyword; otherwise, <see langword="false"/>.</value>
71-
internal bool IsRef
68+
public bool IsRef
7269
=> _isRef ??= IsRefInternal(this);
7370

7471
/// <summary>
7572
/// Gets a value indicating whether the current instance is marked as <see langword="ref"/> <see langword="readonly"/>.
7673
/// </summary>
7774
/// <value><see langword="true"/> if the parameter is marked as <see langword="ref"/> <see langword="readonly"/>; otherwise, <see langword="false"/>.</value>
78-
internal bool IsRefReadOnly
75+
public bool IsRefReadOnly
7976
=> _isRefReadOnly ??= IsRefReadOnlyInternal(this);
8077

8178
/// <summary>
8279
/// Gets a value indicating whether the parameter is an input parameter (passed by reference using the <see langword="in"/> keyword).
8380
/// </summary>
8481
/// <value><see langword="true"/> if the parameter is an input parameter; otherwise, <see langword="false"/>.</value>
85-
internal bool IsIn
82+
public bool IsIn
8683
=> _isIn ??= IsInParameter(this);
8784

8885
/// <summary>
8986
/// Gets a value indicating whether the parameter is an output parameter (passed by reference using the <see langword="out"/> keyword.
9087
/// </summary>
9188
/// <value><see langword="true"/> if the parameter is an output parameter; otherwise, <see langword="false"/>.</value>
92-
internal bool IsOut
89+
public bool IsOut
9390
=> _isOut ??= IsOutParameter(this);
9491

9592
/// <summary>
@@ -98,23 +95,23 @@ internal bool IsOut
9895
/// <value><see langword="true"/> if the parameter is optional i.e. has a default value; otherwise, <see langword="false"/>.</value>
9996
/// <remarks>This property does not return whether the parameter is decorated with the <see cref="System.Runtime.InteropServices.OptionalAttribute"/>.
10097
/// It only checks whether the parameter is considered optional by the existence of a default value by reading <see cref="System.Reflection.ParameterInfo.HasDefaultValue"/>.</remarks>
101-
internal bool IsOptional
102-
=> _isOptional ??= GetParameterInfo().HasDefaultValue;
98+
public bool IsOptional
99+
=> _isOptional ??= ParameterInfo.HasDefaultValue;
103100

104101
/// <summary>
105102
/// Gets a value indicating whether the parameter type is a generic type parameter.
106103
/// </summary>
107104
/// <value><see langword="true"/> if the parameter type is a generic type parameter; otherwise, <see langword="false"/>.</value>
108-
internal bool IsGenericTypeParameter
105+
public bool IsGenericTypeParameter
109106
=> _isGenericTypeParameter ??= ParameterTypeData.IsGenericTypeParameter;
110107

111-
internal bool IsGenericMethodParameter
108+
public bool IsGenericMethodParameter
112109
=> _isGenericMethodParameter ??= ParameterTypeData.IsGenericMethodParameter;
113110

114111
/// <summary>
115112
/// The modifier that indicates how the parameter is passed (e.g., by value, by reference, as an input parameter, or as an output parameter).
116113
/// </summary>
117-
internal ParameterKind ParameterKind
114+
public ParameterKind ParameterKind
118115
=> _parameterKind ??= IsIn
119116
? ParameterKind.In
120117
: IsOut
@@ -133,22 +130,22 @@ internal ParameterKind ParameterKind
133130
/// that value; otherwise, it returns <see langword="null"/>. The value may be of any type, depending on the parameter's
134131
/// type. Use <see cref="IsOptional"/> to check if a default value is defined before accessing this property.</remarks>
135132
/// <exception cref="InvalidOperationException">Thrown when no default value is defined for the parameter.</exception>
136-
internal object? DefaultValue
133+
public object? DefaultValue
137134
=> _defaultValue ??= IsOptional
138-
? GetParameterInfo().RawDefaultValue
135+
? ParameterInfo.RawDefaultValue
139136
: throw new InvalidOperationException("No default value defined.");
140137

141138
/// <summary>
142139
/// Zero-based index of the parameter in the formal parameter list.
143140
/// </summary>
144141
/// <value>The position of the parameter.</value>
145-
internal int Position
146-
=> _position ??= GetParameterInfo().Position;
142+
public int Position
143+
=> _position ??= ParameterInfo.Position;
147144

148-
internal bool IsParams
149-
=> _isParams ??= GetParameterInfo().GetCustomAttribute<ParamArrayAttribute>() != null;
145+
public bool IsParams
146+
=> _isParams ??= ParameterInfo.GetCustomAttribute<ParamArrayAttribute>() != null;
150147

151-
internal ParameterInfo ParameterInfo { get; }
148+
public ParameterInfo ParameterInfo { get; }
152149

153150
/// <summary>
154151
/// Gets the member (method, constructor, or property accessor) that declares this parameter.
@@ -169,8 +166,8 @@ internal bool IsParams
169166
/// belongs to an indexer property (getter or setter) or the setter of a non-indexer property.<para/>
170167
/// If parameter association for indexer properties matters, then always obtain parameters directly from the getter or setter method (e.g. <see cref="MethodData.Parameters"/> like <c>PropertyData.PropertySetMethodData.Parameters</c>) and completely avoid <see cref="PropertyData.IndexerParameters"/> (or <see cref="PropertyInfo.GetIndexParameters"/>).</remarks>
171168
/// <value>The <see cref="ParameterizedMemberData"/> (which is either a <see cref="MethodData"/> or <see cref="ConstructorData"/>) that declares this parameter.</value>
172-
internal ParameterizedMemberData MemberData
173-
=> _member ??= GetParameterInfo().Member switch
169+
public ParameterizedMemberData MemberData
170+
=> _member ??= ParameterInfo.Member switch
174171
{
175172
ConstructorInfo constructorInfo => SymbolReflectionInfoCache.GetOrCreateSymbolReflectionInfoCacheEntry(constructorInfo),
176173

@@ -189,37 +186,37 @@ internal ParameterizedMemberData MemberData
189186
_ => throw new NotImplementedException(),
190187
};
191188

192-
internal TypeData ParameterTypeData
193-
=> _parameterTypeData ??= SymbolReflectionInfoCache.GetOrCreateSymbolInfoDataCacheEntry(GetParameterInfo().ParameterType);
189+
public TypeData ParameterTypeData
190+
=> _parameterTypeData ??= SymbolReflectionInfoCache.GetOrCreateSymbolInfoDataCacheEntry(ParameterInfo.ParameterType);
194191

195-
internal TypeData DeclaringTypeData
192+
public TypeData DeclaringTypeData
196193
=> _declaringTypeData ??= SymbolReflectionInfoCache.GetOrCreateSymbolInfoDataCacheEntry(GetDeclaringType());
197194

198-
internal override IList<CustomAttributeData> AttributeData
199-
=> _attributeData ??= [.. GetParameterInfo().GetCustomAttributesData()];
195+
public override IList<CustomAttributeData> AttributeData
196+
=> _attributeData ??= [.. ParameterInfo.GetCustomAttributesData()];
200197

201198
/// <summary>
202199
/// Gets a value indicating whether the parameter is passed by reference.
203200
/// </summary>
204-
internal bool IsByRef
201+
public bool IsByRef
205202
=> _isByRef ??= ParameterTypeData.UnwrapType().IsByRef;
206203

207-
internal bool IsIndexerPropertyParameter
204+
public bool IsIndexerPropertyParameter
208205
=> _isIndexerPropertyParameter ??= MemberData is MethodData methodData && (methodData.IsIndexerPropertyGetMethod || methodData.IsIndexerPropertySetMethod);
209206

210207
/// <summary>
211208
/// Gets a value indicating whether this parameter belongs to the setter method of an indexer property.
212209
/// </summary>
213210
/// <value><see langword="true"/> if the parameter belongs to an indexer property setter; otherwise, <see langword="false"/>.<para/>
214211
/// This value exclusively describes indexer properties and therefore also returns <see langword="false"/> for non-indexer property setters.</value>
215-
internal bool IsIndexerPropertySetterParameter
212+
public bool IsIndexerPropertySetterParameter
216213
=> _isIndexerPropertySetterParameter ??= MemberData is MethodData methodData && methodData.IsIndexerPropertySetMethod;
217214

218215
/// <summary>
219216
/// Returns <see langword="true"/> if the parameter belongs to an indexer property getter.
220217
/// </summary>
221218
/// <remarks>This property is typically used to identify parameters that are part of indexer property getters. </remarks>
222-
internal bool IsIndexerPropertyGetterParameter
219+
public bool IsIndexerPropertyGetterParameter
223220
=> _isIndexerPropertyGetterParameter ??= MemberData is MethodData methodData && methodData.IsIndexerPropertyGetMethod;
224221

225222
/// <summary>
@@ -231,7 +228,7 @@ internal bool IsIndexerPropertyGetterParameter
231228
/// compiler-generated parameter named 'value' as the last parameter in the method signature.
232229
/// </remarks>
233230
/// <value><see langword="true"/> if the parameter is the implicit 'value' parameter of a property or indexer setter; otherwise, <see langword="false"/>.</value>
234-
internal bool IsSetterValueParameter
231+
public bool IsSetterValueParameter
235232
=> IsPropertySetterParameter // No-indexer property setter always has a single "value" parameter
236233
|| (Name.Equals("value", StringComparison.Ordinal) // "value" parameter is always named "value"
237234
&& Position == MemberData.Parameters.Count - 1 // Calling MethodInfo.GetParameters() on a property setter includes the compiler generated "value" parameter at the end of the parameter list
@@ -243,85 +240,68 @@ internal bool IsSetterValueParameter
243240
/// </summary>
244241
/// <value><see langword="true"/> if the parameter belongs to a non-indexer property setter method; otherwise, <see langword="false"/>.<para/>
245242
/// This value exclusively describes non-indexer properties and therefore also returns <see langword="false"/> for indexer property setters.</value>
246-
internal bool IsPropertySetterParameter
243+
public bool IsPropertySetterParameter
247244
=> _isPropertySetterParameter ??= MemberData is MethodData methodData && methodData.IsPropertySetMethod;
248245

249-
internal override SymbolAttributes SymbolAttributes => _symbolAttributes is SymbolAttributes.Undefined
246+
public override SymbolAttributes SymbolAttributes => _symbolAttributes is SymbolAttributes.Undefined
250247
? (_symbolAttributes = ParameterData.GetAttributesInternal(this))
251248
: _symbolAttributes;
252249

253-
internal override SymbolComponentInfo SymbolComponentInfo
250+
public override SymbolComponentInfo SymbolComponentInfo
254251
=> _symbolComponentInfo ??= SymbolSignatureGenerator.ToSignatureComponentsInternal(this, isFullyQualifiedName: false, isDeclaringTypeIncluded: false, isCompact: false);
255252

256-
internal override string Signature
253+
public override string Signature
257254
=> Name;
258255

259-
internal override string ShortSignature
256+
public override string ShortSignature
260257
=> Name;
261258

262-
internal override string ShortCompactSignature
259+
public override string ShortCompactSignature
263260
=> Name;
264261

265-
internal override string FullyQualifiedSignature
262+
public override string FullyQualifiedSignature
266263
=> Name;
267264

268-
internal override string FullyQualifiedRuntimeSignature
265+
public override string FullyQualifiedRuntimeSignature
269266
=> Name;
270267

271-
internal override string RuntimeSignature
268+
public override string RuntimeSignature
272269
=> Name;
273270

274-
internal override string RuntimeShortSignature
271+
public override string RuntimeShortSignature
275272
=> Name;
276273

277-
internal override string RuntimeShortCompactSignature
274+
public override string RuntimeShortCompactSignature
278275
=> Name;
279276

280-
internal override string DisplayName
277+
public override string DisplayName
281278
=> Name;
282279

283-
internal override string ShortDisplayName
280+
public override string ShortDisplayName
284281
=> Name;
285282

286-
internal override string FullyQualifiedDisplayName
283+
public override string FullyQualifiedDisplayName
287284
=> Name;
288285

289-
internal override string AssemblyName
286+
public override string AssemblyName
290287
=> _assemblyName ??= MemberData.AssemblyName;
291288

292-
internal override string Namespace { get; }
289+
public override string Namespace { get; }
293290

294291
/// <summary>
295292
/// Determine whether the parameter is passed by reference using the <see langword="ref"/> keyword.
296293
/// </summary>
297294
/// <param name="parameterData"></param>
298295
/// <returns></returns>
299-
internal static bool IsRefInternal(ParameterData parameterData)
296+
private static bool IsRefInternal(ParameterData parameterData)
300297
{
301298
if (!parameterData.IsByRef || parameterData.IsOut)
302299
{
303300
return false;
304301
}
305302

306303
// No readonly markers → plain ref
307-
ParameterInfo parameterInfo = parameterData.GetParameterInfo();
308-
return parameterInfo.GetCustomAttribute<IsReadOnlyAttribute>() is null
309-
&& parameterInfo.GetCustomAttribute<RequiresLocationAttribute>() is null;
310-
}
311-
312-
/// <summary>
313-
/// Determine whether the parameter is passed by reference using the <see langword="ref"/> keyword.
314-
/// </summary>
315-
/// <param name="parameterInfo"></param>
316-
/// <returns></returns>
317-
internal static bool IsRefInternal(ParameterInfo parameterInfo)
318-
{
319-
if (!parameterInfo.ParameterType.IsByRef || parameterInfo.IsOut)
320-
{
321-
return false;
322-
}
323-
324-
// No readonly markers → plain ref
304+
ParameterInfo parameterInfo = parameterData.ParameterInfo;
325305
return parameterInfo.GetCustomAttribute<IsReadOnlyAttribute>() is null
326306
&& parameterInfo.GetCustomAttribute<RequiresLocationAttribute>() is null;
327307
}
@@ -331,31 +311,15 @@ internal static bool IsRefInternal(ParameterInfo parameterInfo)
331311
/// </summary>
332312
/// <param name="parameterData"></param>
333313
/// <returns></returns>
334-
internal static bool IsRefReadOnlyInternal(ParameterData parameterData)
314+
private static bool IsRefReadOnlyInternal(ParameterData parameterData)
335315
{
336316
if (!parameterData.IsByRef || parameterData.IsOut)
337317
{
338318
return false;
339319
}
340320

341321
// No readonly markers → plain ref readonly
342-
ParameterInfo parameterInfo = parameterData.GetParameterInfo();
343-
return parameterInfo.GetCustomAttribute<RequiresLocationAttribute>() is not null;
344-
}
345-
346-
/// <summary>
347-
/// Determine whether the parameter is passed by reference using the <see langword="ref"/> <see langword="readonly"/> keywords.
348-
/// </summary>
349-
/// <param name="parameterInfo"></param>
350-
/// <returns></returns>
351-
internal static bool IsRefReadOnlyInternal(ParameterInfo parameterInfo)
352-
{
353-
if (!parameterInfo.ParameterType.IsByRef || parameterInfo.IsOut)
354-
{
355-
return false;
356-
}
357-
358-
// No readonly markers → plain ref readonly
322+
ParameterInfo parameterInfo = parameterData.ParameterInfo;
359323
return parameterInfo.GetCustomAttribute<RequiresLocationAttribute>() is not null;
360324
}
361325

@@ -370,7 +334,7 @@ private static bool IsInParameter(ParameterData parameterData)
370334
}
371335

372336
// C# 'in' → IsReadOnlyAttribute, but not ref readonly
373-
ParameterInfo parameterInfo = parameterData.GetParameterInfo();
337+
ParameterInfo parameterInfo = parameterData.ParameterInfo;
374338
bool hasReadOnly = parameterInfo.GetCustomAttribute<IsReadOnlyAttribute>() is not null;
375339
bool hasReqLoc = parameterInfo.GetCustomAttribute<RequiresLocationAttribute>() is not null;
376340

‎src/BionicCode.Utilities.Reflection/ParameterList.cs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,12 @@ internal ParameterList(IEnumerable<ParameterData> items, bool isIntegrityValidat
9393

9494
public ImmutableList<ParameterInfo> AsParameterInfoList()
9595
=> Parameters
96-
.Select(parameterData => parameterData.GetParameterInfo())
96+
.Select(parameterData => parameterData.ParameterInfo())
9797
.ToImmutableList();
9898

9999
public ImmutableArray<ParameterInfo> AsParameterInfoArray()
100100
=> Parameters
101-
.Select(parameterData => parameterData.GetParameterInfo())
101+
.Select(parameterData => parameterData.ParameterInfo())
102102
.ToImmutableArray();
103103

104104
public bool TryGetParameterByName(string parameterName, out ParameterData? parameterData)

‎src/BionicCode.Utilities.Reflection/WellKnownParameterDescriptor.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public WellKnownParameterDescriptor(ParameterInfo parameterInfo)
3030
{
3131
ParameterData? disambiguatedPropertyData = SymbolReflectionInfoCache.ConvertAmbiguousIndexerPropertyParameterToAccessorAssociatedParameter(parameterInfo);
3232

33-
ParameterInfo = disambiguatedPropertyData.GetParameterInfo();
33+
ParameterInfo = disambiguatedPropertyData.ParameterInfo();
3434
}
3535
else
3636
{

0 commit comments

Comments
 (0)