Skip to content

Commit 1e59e0c

Browse files
committed
fix to ignore IsReadOnlyAttribute on methods and event accessors
1 parent 4b5f510 commit 1e59e0c

File tree

2 files changed

+22
-1
lines changed
  • src/Smdn.Reflection.ReverseGenerating.ListApi.Core/Smdn.Reflection.ReverseGenerating.ListApi
  • tests/Smdn.Reflection.ReverseGenerating.ListApi.Core/Smdn.Reflection.ReverseGenerating.ListApi

2 files changed

+22
-1
lines changed

src/Smdn.Reflection.ReverseGenerating.ListApi.Core/Smdn.Reflection.ReverseGenerating.ListApi/AttributeFilter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ private static bool DefaultImpl(Type attrType, ICustomAttributeProvider attrProv
3030
if ("IsReadOnlyAttribute".Equals(attrType.Name, StringComparison.Ordinal)) {
3131
var ignore = attrProvider switch {
3232
Type => true,
33-
MethodInfo m => m.IsPropertyAccessorMethod(),
33+
MethodInfo => true, // also ignores event and property accessors
3434
ParameterInfo => true,
3535
_ => false,
3636
};

tests/Smdn.Reflection.ReverseGenerating.ListApi.Core/Smdn.Reflection.ReverseGenerating.ListApi/AttributeFilter.TestCases.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,16 @@ public class AsyncStateMachineAttr {
129129
[MemberAttributeFilterTestCaseAttribute("", FilterType = typeof(AttributeFilter), FilterMemberName = nameof(AttributeFilter.Default))]
130130
public async ValueTask ValueTaskAsyncStateMachineMethod() => await Task.Delay(0);
131131
}
132+
133+
public struct IsReadOnlyAttr : IDisposable {
134+
[MemberAttributeFilterTestCaseAttribute("[IsReadOnly]")]
135+
[MemberAttributeFilterTestCaseAttribute("", FilterType = typeof(AttributeFilter), FilterMemberName = nameof(AttributeFilter.Default))]
136+
public readonly void M() => throw null;
137+
138+
[MemberAttributeFilterTestCaseAttribute("[IsReadOnly]")]
139+
[MemberAttributeFilterTestCaseAttribute("", FilterType = typeof(AttributeFilter), FilterMemberName = nameof(AttributeFilter.Default))]
140+
readonly void IDisposable.Dispose() => throw null;
141+
}
132142
}
133143

134144
public class FieldAttributes {
@@ -217,6 +227,17 @@ public event EventHandler E {
217227
public event EventHandler ECompilerGenerated;
218228
#pragma warning restore CS0067
219229
}
230+
231+
public struct IsReadOnlyAttr {
232+
public readonly event EventHandler E {
233+
[MemberAttributeFilterTestCaseAttribute("[IsReadOnly]")]
234+
[MemberAttributeFilterTestCaseAttribute("", FilterType = typeof(AttributeFilter), FilterMemberName = nameof(AttributeFilter.Default))]
235+
add => throw null;
236+
[MemberAttributeFilterTestCaseAttribute("[IsReadOnly]")]
237+
[MemberAttributeFilterTestCaseAttribute("", FilterType = typeof(AttributeFilter), FilterMemberName = nameof(AttributeFilter.Default))]
238+
remove => throw null;
239+
}
240+
}
220241
}
221242

222243
public class ParameterAttributes {

0 commit comments

Comments
 (0)