如何将viemodel的实例传递给其他人 [英] How to pass instance of viemodel to other
问题描述
大家好,
我想将一个viewmodel类实例传递给unifide Service Desk应用程序中的其他HostedControl,我已经使用了序列化和反序列化,如下所示: br />
public static string SerializeObject( object o)
{
if (!o.GetType()。IsSerializable)
{
return 空跨度>;
}
使用(MemoryStream stream = new MemoryStream() )
{
new BinaryFormatter()。Serialize(stream,o);
return Convert.ToBase64String(stream.ToArray());
}
}
但我收到以下错误,{类型'系统程序集'System.Reactive.Linq,Version = 2.1.30214.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35'中的.Reactive.Subjects.ReplaySubject未标记为可序列化。}。在我看来,我使用的一种类型的DLL没有Serializable属性。我想知道,我怎么能将相同的viewmodel实例传递给其他人谢谢。
如果您正在尝试使用MVVM模式。你应该尝试一下
public static string SerializeObject(ModelClass model)
{
if (!model.Name.GetType()。IsSerializable)
{
return 空跨度>;
}
使用(MemoryStream stream = new MemoryStream() )
{
new BinaryFormatter()。Serialize(stream,model.Name);
return Convert.ToBase64String(stream.ToArray());
}
我还没有测试过代码,不过,这应该指向正确的方向。
Hi All,
I want to pass a viewmodel class instance to other HostedControl in unifide Service Desk application for which I have used serialization and deserialization as follow,
public static string SerializeObject(object o)
{
if (!o.GetType().IsSerializable)
{
return null;
}
using (MemoryStream stream = new MemoryStream())
{
new BinaryFormatter().Serialize(stream, o);
return Convert.ToBase64String(stream.ToArray());
}
}
but I am getting following error, "{"Type 'System.Reactive.Subjects.ReplaySubject in Assembly 'System.Reactive.Linq, Version=2.1.30214.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' is not marked as serializable."}". It appear to me that one of the type of dll I am using does not have "Serializable" attribute on it. I want to know, how could I pass the same instance of viewmodel to other thank you.
If you are trying to use the MVVM pattern. You should try something along the lines of
public static string SerializeObject(ModelClass model) { if (!model.Name.GetType().IsSerializable) { return null; } using (MemoryStream stream = new MemoryStream()) { new BinaryFormatter().Serialize(stream, model.Name); return Convert.ToBase64String(stream.ToArray()); }
I haven't tested the code, however, this should point you in the right direction.
这篇关于如何将viemodel的实例传递给其他人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!