The first word of camelcase is all lowercase. Hence, ID becomes id, and CName becomes cname. After that, each additional word has only the first letter capitalized, hence name becomes Name. That is to say that Newtonsoft treats ID and CName as single words, not multiple words.
This is the method used to convert characters to camelcase in Newtonsoft. As you can see, it contains little logic for parsing a string into individual words. The code simply assumes that the first word in uppercase ends (1) after the second letter and (2) when the code finds either a space or an uppercase letter followed by a lowercase letter.
public static string ToCamelCase(string s)
{
if (string.IsNullOrEmpty(s) || !char.IsUpper(s[0]))
{
return s;
}
char[] chars = s.ToCharArray();
for (int i = 0; i < chars.Length; i++)
{
if (i == 1 && !char.IsUpper(chars[i]))
{
break;
}
bool hasNext = (i + 1 < chars.Length);
if (i > 0 && hasNext && !char.IsUpper(chars[i + 1]))
{
// if the next character is a space, which is not considered uppercase
// (otherwise we wouldn't be here...)
// we want to ensure that the following:
// 'FOO bar' is rewritten as 'foo bar', and not as 'foO bar'
// The code was written in such a way that the first word in uppercase
// ends when if finds an uppercase letter followed by a lowercase letter.
// now a ' ' (space, (char)32) is considered not upper
// but in that case we still want our current character to become lowercase
if (char.IsSeparator(chars[i + 1]))
{
chars[i] = ToLower(chars[i]);
}
break;
}
chars[i] = ToLower(chars[i]);
}
return new string(chars);
}