I want to customize serialization based on the type of the property. To do that I would like to read DeclaringType
from JsonPropertyInfo
. This is an example from Microsoft documentation on how to create such a modifier
// Custom modifier that increments the value
// of a specific property on deserialization.
static void IncrementCounterModifier(JsonTypeInfo typeInfo)
{
foreach (JsonPropertyInfo propertyInfo in typeInfo.Properties)
{
if (propertyInfo.PropertyType != typeof(int))
continue;
The DeclaringType
property is not available directly on JsonPropertyInfo
though unfortunately (for some strange reason it is defined as internal
), but on a generic type that inherits from it. Is there a way without reflection to read it in modifier?
4