How do we pass strings to enum fields of a cs file (cs file of xsd file).
我们如何将字符串传递给cs文件的枚举字段(xsd文件的cs文件)。
I have written the following code,
我写了以下代码,
string PATH = "C:\\Sample.xml";
CreateEmptyFile(PATH);
var data = new AutoCount();
data.Product = "AutoCount Accounting";
data.Version = "1.5";
data.CreatedApplication = "BApp";
data.CreatedBy = "Business Solutions";
data.CreatedDateTime = DateTime.Today;
data.CreatedDateTimeSpecified = true;
var detail = new SalesIVCSDetailNode();
detail.ItemsElementName = new [] {
ItemsChoiceType3.ItemCode,
ItemsChoiceType3.UOM,
ItemsChoiceType3.Qty,
ItemsChoiceType3.UnitPrice
};
/* above line */
detail.TaxType = "SR";
List<SalesInvoice> salesInvoices = new List<SalesInvoice>();
for (int i = 0; i < dataGridView1.RowCount - 1; i++) {
var salesInvoice = new SalesInvoice();
salesInvoice.DocNo = dataGridView1.Rows[i].Cells[0].FormattedValue.ToString();
salesInvoice.DocDate = DateTime.Today;
salesInvoice.DebtorCode = "ABC Company";
salesInvoice.Detail =new [] {detail};
salesInvoices.Add(salesInvoice);
}
data.SalesInvoice = salesInvoices.ToArray();
var serializer = new XmlSerializer(typeof(AutoCount));
using (var stream = new StreamWriter(PATH))
serializer.Serialize(stream, data);
I want the output to be:
我希望输出为:
<?xml version="1.0" encoding="utf-8" ?>
<AutoCount xmlns="http://schemas.autocountsoft.com/ac_accounting.xsd">
<Product>AutoCount Accounting</Product>
<Version>1.5</Version>
<CreatedApplication>BApp</CreatedApplication>
<CreatedDateTime>2015-02-23T09:51:54.5746</CreatedDateTime>
<CreatedBy>Business Solutions</CreatedBy>
<SalesInvoice DocNo="IV-0022" ImportAction="AddUpdate">
<DocDate>2015-02-15</DocDate>
<DebtorCode>I50201</DebtorCode>
<Detail>
<ItemCode>IMP001</ItemCode>
<UOM>PCS</UOM>
<Qty>2</Qty>
<UnitPrice>15.00</UnitPrice>
</Detail>
</SalesInvoice>
</AutoCount>
Problem is i am not aware of how to send strings for enum fields. i dono how to create nodes .How do we do it?
问题是我不知道如何为枚举字段发送字符串。我不知道如何创建节点。我们怎么做?
the line in the c# query.'ItemsChoiceType3' is enum.
c#query.'ItemsChoiceType3'中的行是枚举。
detail.ItemsElementName = new [] {
ItemsChoiceType3.ItemCode,
ItemsChoiceType3.UOM,
ItemsChoiceType3.Qty,
ItemsChoiceType3.UnitPrice
};
EDIT: The Following is the autocount.cs file taken from autocount.xsd file. I need help in accessing the itemcode,qty,uom,unitprice tags and passing values to it (hardcoding or database)
编辑:以下是从autocount.xsd文件中获取的autocount.cs文件。我需要帮助访问itemcode,qty,uom,unitprice标签并将值传递给它(硬编码或数据库)
public partial class SalesIVCSDetailNode
{
private object[] itemsField;
private ItemsChoiceType3[] itemsElementNameField;
private string locationField;
private string descriptionField;
[System.Xml.Serialization.XmlElementAttribute("ItemCode", typeof(string))]
[System.Xml.Serialization.XmlElementAttribute("PackageCode", typeof(string))]
[System.Xml.Serialization.XmlElementAttribute("Qty", typeof(decimal))]
[System.Xml.Serialization.XmlElementAttribute("UOM", typeof(string))]
[System.Xml.Serialization.XmlElementAttribute("UnitPrice", typeof(decimal))]
[System.Xml.Serialization.XmlChoiceIdentifierAttribute("ItemsElementName")]
public object[] Items
{
get
{
return this.itemsField;
}
set
{
this.itemsField = value;
}
}
[System.Xml.Serialization.XmlElementAttribute("ItemsElementName")]
[System.Xml.Serialization.XmlIgnoreAttribute()]
public ItemsChoiceType3[] ItemsElementName
{
get
{
return this.itemsElementNameField;
}
set
{
this.itemsElementNameField = value;
}
}
}
public enum ItemsChoiceType3
{
ItemCode,
PackageCode,
Qty,
UOM,
UnitPrice,
}
1 个解决方案
#1
0
Try to decorate with XMLEnumAttribute - https://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlenumattribute.aspx
尝试使用XMLEnumAttribute进行装饰 - https://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlenumattribute.aspx
#1
0
Try to decorate with XMLEnumAttribute - https://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlenumattribute.aspx
尝试使用XMLEnumAttribute进行装饰 - https://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlenumattribute.aspx