Код: Выделить всё
public class ResponseBase
{
public string eventType { get; }
public string eventSourceGuid { get; }
}
public class QueryDevicesResponse : ResponseBase
{
public new static string eventType { get => "queryDevicesResponse"; }
public new string eventSourceGuid { get => "0"; }
public EventData eventData { get; set; }
}
< /code>
eventType- minimize lines of code
- use it like "application-wide" string stored (in source code) together with DTO class definition, and use it in some switch and if statements without instantiating QueryDevicesResponse.
Код: Выделить всё
QueryDevicesResponse queryDevicesResponse = QueryDevicesResponse.Mock();
JsonSerializer.Serialize.JsonSerializer.Serialize(queryDevicesResponse);
< /code>
I'm getting JSON without eventTypeМогу ли я изменить поведение Jsonserializer, чтобы включить также статические поля? /> Альтернативно:
Как я могу заменить static модификатор, чтобы получить аналогичное поведение и сохранить код маленьким?
Подробнее здесь: https://stackoverflow.com/questions/646 ... ialization