Код: Выделить всё
public class MyConverter : JsonInheritanceConverter
{
private const string DtoSuffix = "Dto";
public JsonInheritanceDtoConverter(string name) : base(name)
{
}
public Type GetDiscriminatorType(Type objectType, string discriminatorValue)
{
return GetDiscriminatorType(null, objectType, discriminatorValue);
}
public override string GetDiscriminatorValue(Type type)
{
return RemoveFromEnd(type.Name, DtoSuffix);
}
protected override Type GetDiscriminatorType(
JObject jObject,
Type objectType,
string discriminatorValue)
{
return base.GetDiscriminatorType(jObject, objectType, discriminatorValue + DtoSuffix);
}
public static string RemoveFromEnd(string s, string suffix)
{
return s.Substring(0, s.Length - suffix.Length);
}
}
}
Код: Выделить всё
GetDiscriminatorType(
JsonElement jObject,
Type objectType,
string discriminatorValue)
Подробнее здесь: https://stackoverflow.com/questions/790 ... -to-11-0-2
Мобильная версия