2010-08-19 19 views
1

有沒有一種方法可以強制一個可以爲空的雙精度曲線作爲NaN? (反之亦然) 默認情況下,這些值作爲null傳遞,但動作中的數字不可爲空,因此默認情況下將其轉換爲0。c#可以通過氟網關雙向動作NaN

我需要服務器端可爲空的雙打是Flex中的NaN,並且Flex的NaN值是服務器端的雙精度空閒雙打。

有什麼想法?

THX,

回答

1

我不知道是氟,但我想象你可以傳遞:

(myDouble ?? Double.NaN) 

這種表達是double類型,而不是double?的,它將爲NaN如果myDoublenull

+0

嘗試複製,但沒有奏效。問題在於序列化到AMF數據包,發送到flex,但我還沒有找到解決辦法。 – 2010-08-19 14:58:58

+0

我對Fluorine和Flex的瞭解是以拼寫方式結束的,所以我不能在這裏給你很多直接的幫助。間接地,也許你需要執行上面的計算並使用它來填充一個常規的'double',以便序列化器以正確的答案開始。 – 2010-08-19 15:06:07

0

我們只是有同樣的問題。我們的解決方案是修改用於寫入對象的氟代碼。

在文件AMFWriter,行1367,正確調用WriteAMF3Data(memberValue)之前我添加以下代碼:

//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; 
    } 
} 

它似乎工作至今。但是,我通常不用.NET編寫代碼,所以可能有更好的方法來做到這一點。

0

它看起來像氟有一個配置部分,它定義瞭如何轉換空白。我還沒有測試過。

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)