Created
August 21, 2018 15:54
-
-
Save lfgrando/c8d27fbb3f06f13b40f4cf13b5f0eb69 to your computer and use it in GitHub Desktop.
How to rename a JToken
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void RenameToken(JToken token, string newName) | |
{ | |
var parent = token.Parent; | |
if (parent == null) | |
throw new InvalidOperationException("The parent is missing."); | |
var newToken = new JProperty(newName, token); | |
parent.Replace(newToken); | |
} | |
JToken cpf = serializedCustomer["documents"]?["cpf"]; | |
if (cpf != null) | |
RenameToken(cpf, "Cpf"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment