【问题标题】:c# nullable double to actionscript NaN through fluorine gatewayc# nullable double to actionscript NaN through fluorine gateway
【发布时间】:2011-04-01 04:13:48
【问题描述】:

有没有办法在氟中强制将一个可为空的双精度作为 NaN 传递给 flex? (反之亦然) 默认情况下,这些值作为 null 传递,但 actionscript 中的 Number 不可为 null,因此默认转换为 0。

我需要服务器端可为空的双精度值在 flex 中为 NaN,并且来自 flex 的 NaN 值在服务器端为可为空的双精度值。

有什么想法吗?

谢谢,

【问题讨论】:

    标签: c# apache-flex nullable nan fluorinefx


    【解决方案1】:

    我不知道氟,但我想你可以通过:

      (myDouble ?? Double.NaN)
    

    这个表达式的类型是double,而不是double?,如果myDoublenull,它将是NaN。

    【讨论】:

    • 试过了,但没用。问题在于对 AMF 数据包的序列化,该数据包被发送到 flex,但我还没有找到解决方法。
    • 我对@9​​87654326@ 和Flex 的了解以它们的拼写方式结束,所以在这里我不能给你太多直接的帮助。间接地,也许您需要执行上述计算并使用它来填充常规double,以便序列化程序以正确的答案开始。
    【解决方案2】:

    我们刚刚遇到了同样的问题。我们的解决方案是修改 Fluorine 代码以编写对象。

    在文件AMFWriter1367 行中,在调用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 编写代码,因此可能有更好的方法。

    【讨论】:

      【解决方案3】:

      看起来 fluorine 有一个配置部分,它定义了如何转换可空值。我还没有测试过。

      复制自 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)
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-01-16
        • 2012-11-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-06-09
        相关资源
        最近更新 更多