diff --git a/docs/serializer-settings.md b/docs/serializer-settings.md index 28c8f600c..96dd41204 100644 --- a/docs/serializer-settings.md +++ b/docs/serializer-settings.md @@ -1138,8 +1138,8 @@ public Task IgnoreMemberByPredicate() }; var settings = new VerifySettings(); - settings.IgnoreMembers(name => name is "Field" or "Property"); - settings.IgnoreMembers(member => member.Name is "PropertyByName" or "PropertyThatThrows"); + settings.IgnoreMembers(_ => _ is "Field" or "Property"); + settings.IgnoreMembers(_ => _.Name is "PropertyByName" or "PropertyThatThrows"); return Verify(target, settings); } @@ -1157,8 +1157,8 @@ public Task IgnoreMemberByPredicateFluent() var settings = new VerifySettings(); return Verify(target, settings) - .IgnoreMembers(name => name is "Field" or "Property") - .IgnoreMembers(member => member.Name is "PropertyByName" or "PropertyThatThrows"); + .IgnoreMembers(_ => _ is "Field" or "Property") + .IgnoreMembers(_ => _.Name is "PropertyByName" or "PropertyThatThrows"); } [Fact] @@ -1239,8 +1239,8 @@ public Task ScrubMemberByPredicate() }; var settings = new VerifySettings(); - settings.ScrubMembers(name => name is "Field" or "Property"); - settings.ScrubMembers(member => member.Name is "PropertyByName" or "PropertyThatThrows"); + settings.ScrubMembers(_ => _ is "Field" or "Property"); + settings.ScrubMembers(_ => _.Name is "PropertyByName" or "PropertyThatThrows"); return Verify(target, settings); } @@ -1449,7 +1449,7 @@ public static void MemberConverterByExpressionInit() // using only the member VerifierSettings.MemberConverter( expression: _ => _.Field, - converter: member => $"{member}_Suffix"); + converter: _ => $"{_}_Suffix"); // using target and member VerifierSettings.MemberConverter( diff --git a/src/StrictJsonTests/SerializationTests.IgnoreDictionaryByPredicate.verified.json b/src/StrictJsonTests/SerializationTests.IgnoreDictionaryByPredicate.verified.json new file mode 100644 index 000000000..38370f9b4 --- /dev/null +++ b/src/StrictJsonTests/SerializationTests.IgnoreDictionaryByPredicate.verified.json @@ -0,0 +1,6 @@ +{ + "Include": { + "Key1": "Value2" + }, + "Key2": "Value4" +} \ No newline at end of file diff --git a/src/StrictJsonTests/SerializationTests.IgnoreMemberByPredicate.verified.json b/src/StrictJsonTests/SerializationTests.IgnoreMemberByPredicate.verified.json new file mode 100644 index 000000000..0ab19d7fe --- /dev/null +++ b/src/StrictJsonTests/SerializationTests.IgnoreMemberByPredicate.verified.json @@ -0,0 +1,4 @@ +{ + "Include": "Value", + "GetOnlyProperty": "asd" +} \ No newline at end of file diff --git a/src/StrictJsonTests/SerializationTests.IgnoreMemberByPredicateFluent.verified.json b/src/StrictJsonTests/SerializationTests.IgnoreMemberByPredicateFluent.verified.json new file mode 100644 index 000000000..0ab19d7fe --- /dev/null +++ b/src/StrictJsonTests/SerializationTests.IgnoreMemberByPredicateFluent.verified.json @@ -0,0 +1,4 @@ +{ + "Include": "Value", + "GetOnlyProperty": "asd" +} \ No newline at end of file diff --git a/src/StrictJsonTests/SerializationTests.ScrubDictionaryByPredicate.verified.json b/src/StrictJsonTests/SerializationTests.ScrubDictionaryByPredicate.verified.json new file mode 100644 index 000000000..6cfa11d29 --- /dev/null +++ b/src/StrictJsonTests/SerializationTests.ScrubDictionaryByPredicate.verified.json @@ -0,0 +1,8 @@ +{ + "Ignore": "{Scrubbed}", + "Include": { + "Ignore": "{Scrubbed}", + "Key1": "Value2" + }, + "Key2": "Value4" +} \ No newline at end of file diff --git a/src/StrictJsonTests/SerializationTests.ScrubMemberByPredicate.verified.json b/src/StrictJsonTests/SerializationTests.ScrubMemberByPredicate.verified.json new file mode 100644 index 000000000..9d1b9e866 --- /dev/null +++ b/src/StrictJsonTests/SerializationTests.ScrubMemberByPredicate.verified.json @@ -0,0 +1,8 @@ +{ + "Include": "Value", + "Field": "{Scrubbed}", + "Property": "{Scrubbed}", + "PropertyByName": "{Scrubbed}", + "GetOnlyProperty": "asd", + "PropertyThatThrows": "{Scrubbed}" +} \ No newline at end of file diff --git a/src/StrictJsonTests/SerializationTests.ScrubMemberByPredicateFluent.verified.json b/src/StrictJsonTests/SerializationTests.ScrubMemberByPredicateFluent.verified.json new file mode 100644 index 000000000..9d1b9e866 --- /dev/null +++ b/src/StrictJsonTests/SerializationTests.ScrubMemberByPredicateFluent.verified.json @@ -0,0 +1,8 @@ +{ + "Include": "Value", + "Field": "{Scrubbed}", + "Property": "{Scrubbed}", + "PropertyByName": "{Scrubbed}", + "GetOnlyProperty": "asd", + "PropertyThatThrows": "{Scrubbed}" +} \ No newline at end of file diff --git a/src/Verify.Tests/Serialization/SerializationTests.cs b/src/Verify.Tests/Serialization/SerializationTests.cs index d360c9547..13d0bcaef 100644 --- a/src/Verify.Tests/Serialization/SerializationTests.cs +++ b/src/Verify.Tests/Serialization/SerializationTests.cs @@ -3274,7 +3274,7 @@ public static void MemberConverterByExpressionInit() // using only the member VerifierSettings.MemberConverter( expression: _ => _.Field, - converter: member => $"{member}_Suffix"); + converter: _ => $"{_}_Suffix"); // using target and member VerifierSettings.MemberConverter( @@ -3478,8 +3478,8 @@ public Task ScrubMemberByPredicate() }; var settings = new VerifySettings(); - settings.ScrubMembers(name => name is "Field" or "Property"); - settings.ScrubMembers(member => member.Name is "PropertyByName" or "PropertyThatThrows"); + settings.ScrubMembers(_ => _ is "Field" or "Property"); + settings.ScrubMembers(_ => _.Name is "PropertyByName" or "PropertyThatThrows"); return Verify(target, settings); } @@ -3548,8 +3548,8 @@ public Task IgnoreMemberByPredicate() }; var settings = new VerifySettings(); - settings.IgnoreMembers(name => name is "Field" or "Property"); - settings.IgnoreMembers(member => member.Name is "PropertyByName" or "PropertyThatThrows"); + settings.IgnoreMembers(_ => _ is "Field" or "Property"); + settings.IgnoreMembers(_ => _.Name is "PropertyByName" or "PropertyThatThrows"); return Verify(target, settings); } @@ -3567,8 +3567,8 @@ public Task IgnoreMemberByPredicateFluent() var settings = new VerifySettings(); return Verify(target, settings) - .IgnoreMembers(name => name is "Field" or "Property") - .IgnoreMembers(member => member.Name is "PropertyByName" or "PropertyThatThrows"); + .IgnoreMembers(_ => _ is "Field" or "Property") + .IgnoreMembers(_ => _.Name is "PropertyByName" or "PropertyThatThrows"); } [Fact] diff --git a/src/Verify/Serialization/SerializationSettings_IgnoreByPredicate.cs b/src/Verify/Serialization/SerializationSettings_IgnoreByPredicate.cs index c1a3b26ef..3c6858452 100644 --- a/src/Verify/Serialization/SerializationSettings_IgnoreByPredicate.cs +++ b/src/Verify/Serialization/SerializationSettings_IgnoreByPredicate.cs @@ -6,25 +6,25 @@ public void IgnoreMembers(Func predicate) { Guard.NotNull(predicate); - ignoredMemberPredicatesByMember.Add(member => predicate(member) ? ScrubOrIgnore.Ignore : null); + ignoredMemberPredicatesByMember.Add(_ => predicate(_) ? ScrubOrIgnore.Ignore : null); } public void IgnoreMembers(Func predicate) { Guard.NotNull(predicate); - ignoredMemberPredicatesByString.Add(member => predicate(member) ? ScrubOrIgnore.Ignore : null); + ignoredMemberPredicatesByString.Add(_ => predicate(_) ? ScrubOrIgnore.Ignore : null); } public void ScrubMembers(Func predicate) { Guard.NotNull(predicate); - ignoredMemberPredicatesByMember.Add(member => predicate(member) ? ScrubOrIgnore.Scrub : null); + ignoredMemberPredicatesByMember.Add(_ => predicate(_) ? ScrubOrIgnore.Scrub : null); } public void ScrubMembers(Func predicate) { Guard.NotNull(predicate); - ignoredMemberPredicatesByString.Add(member => predicate(member) ? ScrubOrIgnore.Scrub : null); + ignoredMemberPredicatesByString.Add(_ => predicate(_) ? ScrubOrIgnore.Scrub : null); } internal bool TryGetScrubOrIgnorePredicateByName(string name, MemberInfo? memberInfo, [NotNullWhen(true)] out ScrubOrIgnore? scrubOrIgnore) diff --git a/src/Verify/Serialization/SerializationSettings_IgnoreInstance.cs b/src/Verify/Serialization/SerializationSettings_IgnoreInstance.cs index 3bf3fa26f..45ba22da8 100644 --- a/src/Verify/Serialization/SerializationSettings_IgnoreInstance.cs +++ b/src/Verify/Serialization/SerializationSettings_IgnoreInstance.cs @@ -8,11 +8,7 @@ public void IgnoreInstance(Func shouldIgnore) var type = typeof(T); IgnoreInstance( type, - target => - { - var arg = (T) target; - return shouldIgnore(arg); - }); + _ => shouldIgnore((T) _)); } public void IgnoreInstance(Type type, ShouldIgnore shouldIgnore) @@ -39,11 +35,7 @@ public void ScrubInstance(Func shouldScrub) var type = typeof(T); ScrubInstance( type, - target => - { - var arg = (T) target; - return shouldScrub(arg); - }); + _ => shouldScrub((T) _)); } public void ScrubInstance(Type type, ShouldScrub shouldScrub)