c# nullable double to actionscript NaN through fluorine gateway

502 views Asked by At

Is there a way in fluorine to force a nullable double to be passed to flex as NaN? (and vice versa) By default these values are passed as null, but a Number in actionscript is not nullable, so it is converted to 0 by default.

I need server side nullable doubles to be NaN in flex, and NaN values from flex to be nullable doubles on the server side.

Any thoughts?

Thx,

3

There are 3 answers

2
Steven Sudit On

I don't know Fluorine, but I'd imagine that you could pass in:

  (myDouble ?? Double.NaN)

This expression is of type double, not double?, and it will be NaN if myDouble was null.

0
Jacob Eggers On

We just had the same problem. Our solution was to modify the Fluorine code for writing objects.

In the file AMFWriter, line 1367, right before calling WriteAMF3Data(memberValue) I added the following code:

//Mapping null double?s to NaN when writing data.
if (memberValue == null)
{
    System.Reflection.PropertyInfo p = type.GetProperty(classMember.Name);
    if (p != null)
    {
        Type t = p.PropertyType; // t will be System.String
        if (t.IsEquivalentTo(typeof(Nullable<Double>)))
            memberValue = Double.NaN;
    }
}

It seems to work so far. But, I don't usually code in .NET, so there might be a better way of doing this.

0
Devin Garner On

It looks like fluorine has a config section which defines how nullables are converted. I haven't tested it yet.

Copied from http://www.fluorinefx.com/docs/fluorine/nullable.html

FluorineFx.NET  
Null values
The <nullable> configuration section allows the use of special value of the given value type as the null value. 

Use this solution only when you can identify a value which is unused.

<nullable>
    <type name="System.Int32" assembly="MinValue"/>
    <type name="System.Double" assembly="MinValue"/>
    <type name="System.DateTime" assembly="MinValue"/>
    <type name="System.Guid" assembly="Empty"/>
</nullable>

The name attribute is the fully qualified type name, the value attribute is a static member of the type (such as "MinValue") or a parseable value (0 for System.Int32 for example).

The acceptNullValueTypes option
Fluorine will accept null values sent from client for value-types if configured accordingly

    <acceptNullValueTypes>false</acceptNullValueTypes>

If acceptNullValueTypes = true (the default is false if not specified) any value-type that is not explicitly initialized with a value will contain the default value for that object type (0 for numeric types, false for Boolean, DateTime.Min for DateTime)