JsonКонвертер. VS.net не позволяет реализовать абстрактный класс/NewtonsoftJsonC#

Место общения программистов C#
Ответить
Anonymous
 JsonКонвертер. VS.net не позволяет реализовать абстрактный класс/NewtonsoftJson

Сообщение Anonymous »

Я пытаюсь реализовать JsonConverter с помощью этого кода:

Код: Выделить всё

public class TimestampStringConverter : JsonConverter
{
public sealed override object? ReadJson(JsonReader reader, Type objectType, object? existingValue, JsonSerializer serializer)
{
bool existingIsNull = existingValue == null;
if (!(existingIsNull || existingValue is T))
{
throw new JsonSerializationException("Converter cannot read JSON with the specified existing value. {0} is required.".FormatWith(CultureInfo.InvariantCulture, typeof(T)));
}
return ReadJson(reader, objectType, existingIsNull ? default : (T?)existingValue, !existingIsNull, serializer);
}
}
он ​​всегда говорит: CS0115 — не найден подходящий метод для переопределения — и помечает строку «ReadJson(..)»
и это Код в файле NewtonsoftJson:

Код: Выделить всё

public abstract class JsonConverter : JsonConverter
{
/// 
/// Writes the JSON representation of the object.
/// 
/// 
The  to write to.
/// The value.
/// The calling serializer.
public sealed override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer)
{
if (!(value != null ? value is T : ReflectionUtils.IsNullable(typeof(T))))
{
throw new JsonSerializationException("Converter cannot write specified value to JSON. {0} is required.".FormatWith(CultureInfo.InvariantCulture, typeof(T)));
}
WriteJson(writer, (T?)value, serializer);
}

/// 
/// Writes the JSON representation of the object.
/// 
/// The  to write to.
/// The value.
/// The calling serializer.
public abstract void WriteJson(JsonWriter writer, T? value, JsonSerializer serializer);

/// 
/// Reads the JSON representation of the object.
/// 
/// The  to read from.
/// Type of the object.
/// The existing value of object being read.
/// The calling serializer.
/// The object value.
public sealed override object? ReadJson(JsonReader reader, Type objectType, object? existingValue, JsonSerializer serializer)
{
bool existingIsNull = existingValue == null;
if (!(existingIsNull || existingValue is T))
{
throw new JsonSerializationException("Converter cannot read JSON with the specified existing value. {0} is required.".FormatWith(CultureInfo.InvariantCulture, typeof(T)));
}
return ReadJson(reader, objectType, existingIsNull ? default : (T?)existingValue, !existingIsNull, serializer);
}

---- rest of the file

итак:
что я делаю не так?
Метод находится в базовом классе, я скопировал даже исходную подпись в новый класс - тем не менее VS.NET продолжает говорить "CS0115"
Это ошибка в IDE?
Независимо от какая функция из базового класса: VS.NET всегда утверждает, что нет метода, который я мог бы перезаписать, хотя я ясно вижу их в файле из NewtonsoftJson?
Есть идеи?
  • Я ожидал, что смогу реализовать абстрактный класс и переопределить все его функции
  • Я уже поискал в Google, чтобы проверить, есть ли у кого-нибудь еще эта проблема, так как это похоже на ошибку в VS.NET


Подробнее здесь: https://stackoverflow.com/questions/791 ... s-newtonso
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C#»