我从大量XSD生成> 100个类,以构建用于内部测试的测试用例应用程序。我正在使用XSD.exe来生成这些类,因为这样做会带来太多风险,并且会花费太长时间。将枚举序列化为XML属性
我遇到了一个令我有点痛的问题。我试图得到这个枚举(现在只是这一个,然后我会对其余的做相同的技术...)
我想这是为了产生这样的事情(其中接收器元件具有TYPECODE属性):
<receiver typeCode="RCV">
<device classCode="DEV" determinerCode="INSTANCE">
<id root="..." extension="..." />
<asAgent classCode="AGNT">
<representedOrganization classCode="ORG" determinerCode="INSTANCE">
<id root="..." extension="..." />
</representedOrganization>
</asAgent>
</device>
</receiver>
然而,接收器从来没有得到一个属性,即使我已经在测试工具启动对象explicetly设置:
this.receiver = new MCCI_MT000100BCReceiver();
this.receiver.typeCode = CommunicationFunctionType.RSP;
this.receiver.device = new MCCI_MT000100BCDevice();
我有一个枚举(I”我添加了XMLEnums和[Flags]属性,因为XSD.exe没有打扰)
[Flags]
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.42")]
[System.SerializableAttribute()]
[System.Xml.Serialization.XmlTypeAttribute(Namespace = "urn:hl7-org:v3")]
public enum CommunicationFunctionType
{
/// <remarks/>
[System.Xml.Serialization.XmlEnum("RCV")]
RCV = 1,
/// <remarks/>
[System.Xml.Serialization.XmlEnum("RSP")]
RSP = 2,
/// <remarks/>
[System.Xml.Serialization.XmlEnum("SND")]
SND = 3,
}
这是使用枚举类之一:
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.42")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(TypeName = "MCCI_MT000100BC.Receiver", Namespace = "urn:hl7-org:v3")]
public partial class MCCI_MT000100BCReceiver
{
private CS[] realmCodeField;
private II typeIdField;
private II[] templateIdField;
private MCCI_MT000100BCDevice deviceField;
private CommunicationFunctionType typeCodeField;
private bool typeCodeFieldSpecified;
public MCCI_MT000100BCReceiver()
{
this.typeCodeField = CommunicationFunctionType.RCV;
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("realmCode")]
public CS[] realmCode
{
get
{
return this.realmCodeField;
}
set
{
this.realmCodeField = value;
}
}
/// <remarks/>
public II typeId
{
get
{
return this.typeIdField;
}
set
{
this.typeIdField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("templateId")]
public II[] templateId
{
get
{
return this.templateIdField;
}
set
{
this.templateIdField = value;
}
}
/// <remarks/>
public MCCI_MT000100BCDevice device
{
get
{
return this.deviceField;
}
set
{
this.deviceField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public CommunicationFunctionType typeCode
{
get
{
return this.typeCodeField;
}
set
{
this.typeCodeField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool typeCodeSpecified
{
get
{
return this.typeCodeFieldSpecified;
}
set
{
this.typeCodeFieldSpecified = value;
}
}
}
据我所知,序列化枚举是不是.NET喜欢在时间做,但任何帮助,将不胜感激。
枚举是否在xsd中定义? –
@Jayanta - 是的,它被定义。我大概有100个,而XSD只占90%以上,因为它不喜欢多个有限制的嵌套工会。 –