It looks like the error is related to the KeyValuePair type that is used in the foreach loop to iterate through the properties of the JObject. This is because the Properties() method of the JObject returns a collection of JProperty objects instead of a collection of key-value pairs.
To fix this error, you can change the type of the property variable in the foreach loop to JProperty instead of KeyValuePair<string, JToken>. Here's the updated code snippet:
foreach (JProperty property in json.Properties())
{
string propertyName = property.Name;
JTokenType propertyType = property.Value.Type;
string propertyTypeName = GetCSharpTypeName(propertyType);
stringBuilder.AppendLine($" public {propertyTypeName} {propertyName} {{ get; set; }}");
}
Posted On:
06-May-2023 00:19