1
Vote

Way to make all generated number properties floating point?

description

I'm using the binary programmatically like this:
    var j = new JsonClassGenerator();   
    j.UseProperties = true; 
    j.Namespace = "RavenLinqpadDriver";
    j.MainClass = "MainClass";  
    j.Example = "{'Name':'Ronnie', 'Age': 28}";
    using (var writer = new StringWriter())
    {
        j.OutputStream = writer;
        j.GenerateClasses();
        var genCode = writer.ToString();
    }
Is there a way to force all generated numeric properties to be doubles instead of using an int32 when a decimal point is not present. If not, what are my options?

comments

ronnieoverby wrote Apr 1, 2013 at 11:38 PM

A related question:

How can I force javascript arrays to translate into List<T> instead of an array?

ronnieoverby wrote Apr 1, 2013 at 11:48 PM

I also need to force all generated value types to be nullable :)

Thanks for any help.

antiufo wrote Apr 5, 2013 at 2:22 AM

Is there a way to force all generated numeric properties to be doubles instead of using an int32 when a decimal point is not present
Yes, and it's the default behavior. I tried running the exact code of your example, and it correctly generates an int field. Can you confirm this?


How can I force javascript arrays to translate into List<T> instead of an array?
The condition for choosing between IList<T> and T[] was inverted. I've fixed the bug, thanks (T[] is used if you enable the (obsolete) explicit deserialization)

I also need to force all generated value types to be nullable :)
I just added an AlwaysUseNullableValues property :) (it's not exposed via UI)