您的位置:首页 > 其它

WCF minOccures = "0" 实现

2009-08-07 16:43 211 查看
[System.CodeDom.Compiler.GeneratedCodeAttribute("svcutil", "3.0.4506.648")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://schemas.datacontract.org/2004/07/Microsoft.Office.Server.Search.Internal.A" +
"dministration")]

public partial class CrawlRuleInternal
{

private System.DateTime accountLastModifiedField;

private bool accountLastModifiedFieldSpecified;

......

[System.Xml.Serialization.XmlElementAttribute(Order=0)]
public System.DateTime accountLastModified
{
get
{
return this.accountLastModifiedField;
}
set
{
this.accountLastModifiedField = value;
}
}

/// <remarks/>
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool accountLastModifiedSpecified
{
get
{
return this.accountLastModifiedFieldSpecified;
}
set
{
this.accountLastModifiedFieldSpecified = value;
}
}

}

CrawlRuleInternal object = new CrawlRuleInternal ();

object.accountLastModifiedSpecified = true; // 执行序列化 有这个元素.

默认 this element is not serialization. minOccures = "0" 实现

0:Xsd.exe 生成一个公共字段。未应用 XML 相关属性,因此将使用默认的 XmlElementAttribute。另外,Xsd.exe 还生成 bool 类型的公共字段,其名称为追加了 Specified 的元素字段名称。例如,如果元素字段的名称为 startDate,则 bool 字段的名称将为 startDateSpecified。将某个对象序列化为 XML 时, XmlSerializer 类检查 bool 字段的值,以确定是否写入该元素。出现的 bool 字段具有 System.Xml.Serialization.XmlIgnoreAttribute,可防止它被 XmlSerializer 序列化。

[System.ServiceModel.MessageBodyMemberAttribute(Namespace="http://tempuri.org/", Order=1)] // delete this sentense we can not serialization
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: