我所有班级都遇到此错误,但是我不确定为什么。'Property name' must declare a body because it is not marked abstract or extern. Automatically implemented properties must define both get and set accessors.
http://msdn.microsoft.com/en-us/library/bb397743.aspx
我已经阅读了MSDN文章,但看不到缺少什么正文或访问器。我做错了什么?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using System.Runtime.Serialization;
using System.IO;
namespace ThereIsOnlyRules
{
[Serializable()]
public class ArmyListing
{
public ArmyListing();
[XmlElement("army")]
public List<Army> listing { get; set; }
public void SerializeToXML(ArmyListing armyListing)
{
XmlSerializer serializer = new XmlSerializer(typeof(ArmyListing));
TextWriter textWriter = new StreamWriter(@"C:\Test\40k.xml");
serializer.Serialize(textWriter, armyListing);
textWriter.Close();
}
}
[Serializable()]
public class Army
{
public Army();
[XmlAttribute]
[XmlArray("unit-category")]
public List<UnitCategory> settingconstraints { get; set; }
[XmlAttribute("name")]
public string armyName { get; set; }
}
[Serializable()]
public class UnitCategory
{
public UnitCategory();
[XmlArray("unit-type")]
public List<UnitType> setting { get; set; }
[XmlAttribute("name")]
public string unitCategoryName { get; set; }
}
[Serializable()]
public class UnitType
{
public UnitType();
[XmlArray("unit")]
public List<Unit> setting { get; set; }
[XmlAttribute("name")]
public string unitTypeName { get; set; }
}
[Serializable()]
public class Unit
{
public Unit();
[XmlAttribute("name")]
public string unitName { get; set; }
[XmlAttribute("composition")]
public string compsition { get; set; }
[XmlAttribute("weapon-skill")]
public string weaponSkill { get; set; }
[XmlAttribute("ballistic-skill")]
public string ballisticSkill { get; set; }
[XmlAttribute("strength")]
public string strength { get; set; }
[XmlAttribute("toughness")]
public string T { get; set; }
[XmlAttribute("wounds")]
public string wounds { get; set; }
[XmlAttribute("initiative")]
public string initiative { get; set; }
[XmlAttribute("attacks")]
public string attacks { get; set; }
[XmlAttribute("leadership")]
public string leadership { get; set; }
[XmlAttribute("saving-throw")]
public string saveThrow { get; set; }
[XmlAttribute("armour")]
public string armour { get; set; }
[XmlAttribute("weapons")]
public string weapons { get; set; }
[XmlAttribute("special-rules")]
public string specialRules { get; set; }
[XmlAttribute("dedicated-transport")]
public string dedicatedTransport { get; set; }
[XmlAttribute("options")]
public string options { get; set; }
}
}
//Form
using System;
using System.Windows.Forms;
namespace ThereIsOnlyRules
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
ArmyListing armyListing = new ArmyListing();
armyListing.SerializeToXML(armyListing);
}
}
}
最佳答案
您的构造函数无效。
public Army();
public UnitCategory();
...