通过 COM 将对象从 C# 返回到 Silverlight
我创建了一个 C# COM Visible 类,我可以通过
dynamic com = AutomationFactory.CreateObject("MyCom");
Silverlight 中的函数访问该类,并且能够返回基本数据类型(即字符串、int...)。到目前为止,一切都很好 :)。
但现在我想通过 COM 连接返回一个对象,事实证明这非常困难。我可以返回一个对象并将其放入动态变量中,然后从那里访问对象成员,但我无法将数据转换为我想要的对象类型。
问题: 1. 有没有办法将动态变量转换为我想要的类。 2. 有没有办法让COM对象返回我想要的类的对象?
I have made a C# COM Visible class that I can access via the
dynamic com = AutomationFactory.CreateObject("MyCom");
function in Silverlight and I am able to return basic datatypes (ie string, int..). So far so good :).
But now I would like to return an object over the COM connection and that proved to be quite difficult. I can return an object and place it into a dynamic variable and from there access the object members, but I can't cast the data to my desired object type.
Questions:
1. Is there a way to cast a dynamic variable to my desired class.
2. Is there a way to make the COM object return an object of my desired class?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的两个问题的答案都是:否。
客户端上安装的完整版 .NET 与 Silverlight 版本的 .NET 之间没有互操作性。
您能做的最好的事情就是创建接受
dynamic
并将其成员委托给dynamic
的包装类。如果您想在完整的 .NET 和 Silverlight 中重用使用此 .NET 对象的代码,请使用接口定义该对象。让原始类实现该接口,并让包装类也实现该接口。
The answer to both your questions is: No.
There is no interop between the full version of .NET installed on a client and the Silverlight version of .NET.
The best you can do is create wrapper class that accepts the
dynamic
and delegates its members into thedynamic
.If you want to re-use code that consumes this .NET object in both full .NET and Silverlight then define the object using an interface. Have the original class implement the interface and have the wrapping class also implement the interface.