在基类上添加[DataContract]属性 [英] add [DataContract] attribute on base class

查看:88
本文介绍了在基类上添加[DataContract]属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





如何在TableEntity课程中添加

Hi,

How can I add the

[DataContract] attribute

对...有什么影响?



on TableEntity class which I don't have any influence on?

[DataContract]
public class MyClass : TableEntity
{
    [DataMember]
    public string Name { get; set; }

    [DataMember]
    public string Email { get; set; }
}

// I need to serialize MyClass as a byte[] and save that into the table storage.

public class MyClassAsByteArray : TableEntity
{
   public byte[] SomeByteArray { get; set; }
}





或者什么是工作 - 周围?



请参阅TableEntity的实现以下链接: TableEntity.cs [ ^ ]

推荐答案

如果类是基类,将其添加到合同是不够的,因为序列化程序集可以知道 关于所有派生类?你真的需要添加一种属性, System.Runtime.Serialization.KnownTypeAttribute ,每个真正使用的终端派生类一个。请参阅:

http://msdn.microsoft .com / zh-cn / library / system.runtime.serialization.knowntypeattribute.aspx [ ^ ]。



顺便说一句,添加<$ c是件好事$ c> [DataConract] 具有唯一命名空间参数的属性。



-SA
If the class is the base class, adding it to the contract is not enough, because how the serialization assembly can "know" about all the derived classes? You really need to add one more kind of attribute, System.Runtime.Serialization.KnownTypeAttribute, one per really used terminal derived class. Please see:
http://msdn.microsoft.com/en-us/library/system.runtime.serialization.knowntypeattribute.aspx[^].

By the way, it's good to add [DataConract] attribute with your unique namespace parameter.

—SA


这篇关于在基类上添加[DataContract]属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆