c# nullable double 通过氟网关到actionscript NaN

发布于 2024-09-15 15:06:12 字数 210 浏览 13 评论 0原文

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

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

有什么想法吗?

谢谢,

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,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

孤千羽 2024-09-22 15:06:12

我不知道氟,但我想你可以传入:

  (myDouble ?? Double.NaN)

This expression is of type double, not double?, and it will be NaN if <代码>myDouble 为null

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.

素手挽清风 2024-09-22 15:06:12

我们刚刚遇到了同样的问题。我们的解决方案是修改 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 编写代码,因此可能有更好的方法来执行此操作。

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.

遗失的美好 2024-09-22 15:06:12

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

复制自

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)

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)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文