Replies: 2 comments
-
I found a solution by using a custom converter. I still think this is overkill and I much rather use In the code below I used public class SomeConverter : WriteOnlyJsonConverter<ISomeInterface>
{
public override void Write(VerifyJsonWriter writer, ISomeInterface value)
{
writer.WriteStartObject();
var type = value.GetType();
var props = type.GetTypeInfo().GetProperties(BindingFlags.Instance | BindingFlags.Public);
foreach (var prop in props)
{
var val = prop.GetValue(value);
if (prop.Name == nameof(ISomeInterface.SomeDelegate) && val is not null)
{
writer.WriteMember(value, "{some message}", prop.Name);
}
else
{
writer.WritePropertyName(prop.Name);
writer.Serializer.Serialize(writer, val);
}
}
writer.WriteEndObject();
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
-
This will throw exception: VerifierSettings.MemberConverter(
typeof(ISomeInterface),
nameof(ISomeInterface.SomeDelegate),
(target, value) => value is null ? null : "{some message}"
); Exception
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have a member inside my class that is of a complex type (e.g.
Func<ValueTask>
) that I really don't care about its contents. I only care if the member has a value or not.I cannot use
IgnoreMember
because I do care if it has a value. Same reason I cannot useScrubMember
.It looks like
TreatAsString
is designed for something else.I tried using
MemberConverter
but it will complain if I change it's type from something complex to let's say a string.Custom converter seems overkill, because I only care about this one member, and would like to leave the rest of the class default.
Is there another solution I might have missed?
Pseudo example:
Pseudo result:
Wanted result:
Beta Was this translation helpful? Give feedback.
All reactions