Skip to content

Commit f18d662

Browse files
committed
Update parameter and property metadata logic and docs
- Consider IsRetval flag for method return parameters. - Refine read-only detection: adjust attribute/modifier checks and order. - Expand isMarkedReadOnly to include optional IsReadOnlyAttribute modifiers. - Clarify XML docs for IsReadOnly and IsInit in PropertyData.
1 parent 55c5ce2 commit f18d662

2 files changed

Lines changed: 9 additions & 7 deletions

File tree

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ internal ParameterData(SymbolReflectionInfoCacheKeyInternal symbolInfoDataCacheK
197197
/// </summary>
198198
internal bool IsByRef => _isByRef ??= ParameterTypeData.Type.IsByRef;
199199

200-
internal bool IsMethodReturnParameter => _isMethodReturnParameter ??= Position == -1;
200+
internal bool IsMethodReturnParameter => _isMethodReturnParameter ??= Position < 0 || ParameterInfo.IsRetval;
201201

202202
internal bool IsIndexerPropertyParameter => _isIndexerPropertyParameter ??= MemberData is MethodData methodData && (methodData.IsIndexerPropertyGetMethod || methodData.IsIndexerPropertySetMethod);
203203

@@ -321,8 +321,8 @@ private static bool IsRefReadOnlyInternal(ParameterData parameterData)
321321

322322
if (parameterData.IsMethodReturnParameter)
323323
{
324-
return parameterData.HasRequiredCustomModifier(ReflectionConstants.InAttributeFullName)
325-
|| parameterData.HasCompilerAttribute<IsReadOnlyAttribute>(ReflectionConstants.IsReadOnlyAttributeFullName)
324+
return parameterData.HasCompilerAttribute<IsReadOnlyAttribute>(ReflectionConstants.IsReadOnlyAttributeFullName)
325+
||parameterData.HasRequiredCustomModifier(ReflectionConstants.InAttributeFullName)
326326
|| parameterData.HasRequiredCustomModifier(ReflectionConstants.IsReadOnlyAttributeFullName);
327327
}
328328
else
@@ -347,7 +347,9 @@ private static bool IsInParameter(ParameterData parameterData)
347347
}
348348

349349
// C# 'in' → IsReadOnlyAttribute, but not ref readonly
350-
bool isMarkedReadOnly = parameterData.HasCompilerAttribute<IsReadOnlyAttribute>(ReflectionConstants.IsReadOnlyAttributeFullName)
350+
bool isMarkedReadOnly = (parameterData.HasCompilerAttribute<IsReadOnlyAttribute>(ReflectionConstants.IsReadOnlyAttributeFullName)
351+
|| parameterData.HasRequiredCustomModifier(ReflectionConstants.IsReadOnlyAttributeFullName)
352+
|| parameterData.HasOptionalCustomModifier(ReflectionConstants.IsReadOnlyAttributeFullName))
351353
&& !IsRefReadOnlyInternal(parameterData);
352354

353355
return isMarkedReadOnly;

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -914,15 +914,15 @@ internal AccessModifier GetAccessorAccessModifier
914914
/// <summary>
915915
/// Gets a value indicating whether the current property has a setter or not.
916916
/// </summary>
917-
/// <remarks>A read-only instance cannot be modified. Use this property to determine if changes to the
918-
/// instance are permitted.</remarks>
917+
/// <remarks>The <see cref="IsReadOnly"/> property is an alias for the inverted <see cref="CanWrite"/>:
918+
/// <br/><c>IsReadOnly == !CanWrite</c></remarks>
919919
/// <value><see langword="true"/> if the property does not have a setter and is therefore read-only; otherwise, <see langword="false"/>.</value>
920920
internal bool IsReadOnly => !CanWrite;
921921

922922
/// <summary>
923923
/// Returns whether the property is an init-only property.
924924
/// </summary>
925-
/// <remarks>This is determined by checking if the property has a setter method and if that setter method is marked with the <see cref="IsExternalInit"/> attribute,
925+
/// <remarks>This is determined by checking if the property has a setter method and if that setter method is marked with the <see cref="IsExternalInit"/> modifier,
926926
/// which is used by the C# compiler to indicate init-only properties.
927927
/// If the property does not have a setter or if the setter is not marked as init-only, this property returns <see langword="false"/>.</remarks>
928928
/// <value><see langword="true"/> if the property is an init-only property; otherwise, <see langword="false"/>.</value>

0 commit comments

Comments
 (0)