Last active
July 20, 2018 18:16
-
-
Save lfgrando/4c9a6bf770770f3c25928b2210f905e7 to your computer and use it in GitHub Desktop.
Rename JObject Token
This file contains hidden or 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); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment