0

What I want to do is take the property Value and assign a new value to it:

public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
    if (reader.TokenType == JsonToken.String)
    {
        reader.Value = "Item" + reader.Value; //--> This is what I want to accomplish
    }

    return base.ReadJson(reader, objectType, existingValue, serializer);
}

Of course this can't be done this way because reader.Value is read only. Is there any other way I can do this?

Thanks in advance.

IvnBam
  • 127
  • 1
  • 12
  • https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem – L.B Aug 02 '17 at 22:36
  • Actually, yes: 1) Load a `JToken` from the `reader`. 2) Modify the `JToken` as necessary. 3) Call `base.ReadJson()` on `token.CreateReader()`. There's an example in [this answer](https://stackoverflow.com/a/32057245/3744182). Is that answer sufficient or do you need something more specific? – dbc Aug 02 '17 at 22:52
  • Hi @dbc that was exactly what I was looking for. Post it as answer so I can accept it. – IvnBam Aug 02 '17 at 23:16
  • @IvnBam - since both questions are explicitly subclassing `StringEnumConverter` I went ahead and marked it as a duplicate. You can vote up that other question & answer if you want. I think your question may have a better written title though. – dbc Aug 02 '17 at 23:38
  • @dbc - ooh yeah I hadn't realized it was you who answered that question too. I up voted you there, thank you – IvnBam Aug 03 '17 at 14:38

0 Answers0