I've tested a little more and i found some bug in JsonConvert.cs the SerializeObject converts an enum not correct.
My Example gives me a Return of {"A":"AAA","B":"BBB","C":"Hello"} but thats not correct
I've change some code in JsonConvert.cs
From
Code: Select all
static object ConvertCSharpObjectToJavaScriptObject(object cSharpObject, bool ignoreErrors)
{
if (cSharpObject is Enum || cSharpObject is Guid || cSharpObject is long)
{
return cSharpObject.ToString();
}
else if (cSharpObject is DateTime)
...
To
Code: Select all
static object ConvertCSharpObjectToJavaScriptObject(object cSharpObject, bool ignoreErrors)
{
if (cSharpObject is Guid || cSharpObject is long)
{
return cSharpObject.ToString();
}
else if (cSharpObject is Enum)
{
return Interop.ExecuteJavaScript("$0.v", cSharpObject);
}
else if (cSharpObject is DateTime)
...
With that change i get {"A":"AAA","B":"BBB","C":1} thats is ok.
But the DeserializeObject does not work well with {Get;Set;} i allways get an conversion error form double to Enum ..
If i remove the {Get;Set} the DeserializeObject has no problems and works well, but the SerializeObject doesn't work.
One way could be to change this one.
Code: Select all
foreach (PropertyInfo property in cSharpObject.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public))
{
string propertyName = property.Name;
object propertyValue = property.GetValue(cSharpObject);
if (propertyValue != null)
{
var recursionResult = ConvertCSharpObjectToJavaScriptObject(propertyValue, ignoreErrors);
if (recursionResult != null)
{
Interop.ExecuteJavaScript(@"$0[$1] = $2;", jsObject, propertyName, recursionResult);
}
}
}
So it would use all fields not only the with {Get;Set;} but i don't know yet how to fix this.
Greets