开发者

c# nullable double to actionscript NaN through fluorine gateway

开发者 https://www.devze.com 2023-01-12 12:07 出处:网络
Is there a way in fluorine to force a nullable double to be passed to flex as NaN? (and vice ve开发者_如何学Crsa)

Is there a way in fluorine to force a nullable double to be passed to flex as NaN? (and vice ve开发者_如何学Crsa) 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,


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.


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.


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)
0

精彩评论

暂无评论...
验证码 换一张
取 消