接收通用类型通过 Flex 中的远程对象自定义对象

发布于 2024-08-30 16:43:01 字数 1518 浏览 12 评论 0原文

是否可以通过 AMF 接收自定义通用类型对象?我正在尝试将 Flex 应用程序与现有的 C# 服务集成,但 Flex 对自定义通用类型对象感到窒息。据我所知,Flex 甚至不支持泛型,但我希望能够读取对象并根据需要强制转换其成员。我基本上只是想让 flex 忽略 。我希望有一种方法可以做到这一点,因为 flex 不会抱怨类型化集合(服务器调用返回 List 工作正常,flex 将其转换为 ArrayCollection 就像非类型化列表一样)。

下面是我所遇到的情况的精简示例:

自定义 C# 类型类

   public class TypeTest<T>
    {
        public T value { get; set; }

        public TypeTest ()
        {
        }
    }

返回 typeTest 的服务器方法

    public TypeTest<String> doTypeTest()
    {
        TypeTest<String> theTester = new TypeTest<String>("grrrr");

        return theTester;
    }

相应的 Flex 值对象:

[RemoteClass(alias="API.Model.TypeTest")]
    public class TypeTest
    {
        private var _value:Object;

        public function get value():Object
        {
             return _value;
        }

        public function set value(theValue:Object):void
        {
            _value = value;
        }

        public function TypeTest()
        {
        }
    }

以及结果处理程序代码:

public function doTypeTest(result:TypeTest):void 
{
    var theString:String = result.value as String;

    trace(theString);
}

调用结果处理程序时,我收到运行时错误:

TypeError:错误#1034:类型强制 失败:无法转换 mx.utils::ObjectProxy@11a98041 到 com.model.vos.TypeTest。

令人恼火的是,如果我将结果处理程序更改为采用对象类型的参数,它就可以正常工作。

有人知道如何使其与值对象一起工作吗?我觉得我错过了一些非常明显的东西。

Is it possible to receive custom generic typed objects through AMF? I'm trying to integrate a flex app with an existing C# service but flex is choking on custom generic typed objects. As far as I can tell Flex doesn't even support generics, but I'd like to be able to even just read in the object and cast its members as necessary. I basically just want flex to ignore the <T>. I'm hopeful that there's a way to do this, since flex doesn't complain about typed collections (a server call returning List works fine and flex converts it to an ArrayCollection just like an un-typed List).

Here's a trimmed down example of what's going on for me:

The custom C# typed class

   public class TypeTest<T>
    {
        public T value { get; set; }

        public TypeTest ()
        {
        }
    }

The server method returning the typeTest

    public TypeTest<String> doTypeTest()
    {
        TypeTest<String> theTester = new TypeTest<String>("grrrr");

        return theTester;
    }

The corresponding flex value object:

[RemoteClass(alias="API.Model.TypeTest")]
    public class TypeTest
    {
        private var _value:Object;

        public function get value():Object
        {
             return _value;
        }

        public function set value(theValue:Object):void
        {
            _value = value;
        }

        public function TypeTest()
        {
        }
    }

and the result handler code:

public function doTypeTest(result:TypeTest):void 
{
    var theString:String = result.value as String;

    trace(theString);
}

When the result handler is called I get the runtime error:

TypeError: Error #1034: Type Coercion
failed: cannot convert
mx.utils::ObjectProxy@11a98041 to
com.model.vos.TypeTest.

Irritatingly if I change the result handler to take parameter of type Object it works fine.

Anyone know how to make this work with the value object? I feel like i'm missing something really obvious.

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

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

发布评论

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

评论(2

忆梦 2024-09-06 16:43:01

尝试在结果处理程序中接收 ObjectProxy 并使用调试器查看其内容。该代理可能是 ResultEvent 或类似的容器类,而不是普通的 TypeTest 对象。

Try receiving an ObjectProxy in the result handler and using the debugger to look at the contents of it. The proxy is likely for a ResultEvent or similar container class, rather than a plain TypeTest object.

假扮的天使 2024-09-06 16:43:01

最近,当一个模块正在加载对象数组而其他模块失败时,我遇到了这个问题。经过两天的互联网研究和代码研究,我发现模块失败了,flex无法注册对象类,因此转换失败。我尝试用某种虚拟方法实例化对象的虚拟变量,一切正常。

I recently came upon this issue when one of the module working in loading an array of objects while other module fails. After 2 days of research on internet and then into the code, I found the module that failed, flex fails to register the object class and hence conversion fails. I tried to instantiate a dummy variable of the object in some dummy method and everything works good.

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