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
Я пытаюсь реализовать JsonConverter с помощью этого кода: [code] 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); } } [/code] он всегда говорит: CS0115 — не найден подходящий метод для переопределения — и помечает строку «ReadJson(..)» и это Код в файле NewtonsoftJson: [code] 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
[/code] итак: что я делаю не так? Метод находится в базовом классе, я скопировал даже исходную подпись в новый класс - тем не менее VS.NET продолжает говорить "CS0115" Это ошибка в IDE? Независимо от какая функция из базового класса: VS.NET всегда утверждает, что нет метода, который я мог бы перезаписать, хотя я ясно вижу их в файле из NewtonsoftJson? Есть идеи?[list] [*]Я ожидал, что смогу реализовать абстрактный класс и переопределить все его функции [*]Я уже поискал в Google, чтобы проверить, есть ли у кого-нибудь еще эта проблема, так как это похоже на ошибку в VS.NET [/list]