Serializing C# type to Javascript

Last post 05-25-2007 3:03 PM by AnkitJ. 1 replies.

Sort Posts:

  • Serializing C# type to Javascript

    05-22-2007, 12:07 PM
    • Loading...
    • paddeo
    • Joined on 08-13-2002, 9:38 AM
    • Posts 47

    We have a type defined in C# that that we are using the JavaScriptSerializer to get down to the client. On the client we have a JavaScript implementation of that type including a JavaScript implementation of  its methods.

     

    I am trying to use $create to create the Component and populate with the serialised JSON from the server like so.

     $create(My.Toolkit.Web.MyDate, this._state.Value, null, null) The trouble is the property names of the C# class are SentenceCased and the JavaScript ones camelCased. The Atlas code (Sys$Component$_setProperties) that matches the JSON to the get_ and set_ functions on My.Toolkit.Web.MyDate does not seem to able to map from the SentenceCased version to the javascript camelCased versions. 

    Now I could just change the Javascript to be the same case but that seems wrong. In the past I have used a JavaScriptConverter to change the JSON sent down, to be compatible with the Javascript member names. Is this the correct way? I looked at the serializer in Reflector and it would seem that the only attribute based control I have is to Ignore elements

     

    TIA

     

    Paddeo

     

    Patrick Long
    Filed under: , ,
  • Re: Serializing C# type to Javascript

    05-25-2007, 3:03 PM
    Answer
    • Loading...
    • AnkitJ
    • Joined on 01-17-2006, 4:08 PM
    • Posts 24

    By default serialization produces member names that exactly match .net class member. Using JavaScriptConverter is the right way to change this behavior.

    -Ankit
    ----------------------------------------------------------
    This posting is provided "AS IS" with no warranties, and confers no rights.
Page 1 of 1 (2 items)
Microsoft Communities
Page view counter