注意:所有代码都是手写的,所以语法可能是错误的我不知道
我想合并由 XSD2Code 工具生成的部分类的两个对象,但无法找出如何。
我发现这篇文章对如何在 C# 中组合部分类对象没有帮助?作为 Partial 类,我有数百个属性和属性。此代码也是复制而不是合并left.price = right.price;
例子
Public Method_1()
{
FruitCrate fcA = new FruitCrate();
fcA = Method_2() + Method_3();
}
Public FruitCrate Method_2()
{
FruitCrate fcB = new FruitCrate();
fcB.Name = ..
fcB..... hundred of properties..
return fcB;
}
Public FruitCrate Method_3()
{
FruitCrate fcC = new FruitCrate();
fcC.Name = ..
fcC..... hundred of properties..
return fcC;
}
这就是部分类的样子,
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "2.0.50727.1433")]
[System.SerializableAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)]
[System.Xml.Serialization.XmlRootAttribute(Namespace="", IsNullable=false)]
public partial class FruitCrate{
private List<FruitCrate> FruitCrate;
private static System.Xml.Serialization.XmlSerializer serializer;
public FruitCrate() {
this.FruitCrateField = new List<FruitCrateField>();
}
[System.Xml.Serialization.XmlArrayAttribute(Order=0)]
[System.Xml.Serialization.XmlArrayItemAttribute("FruitCrate", IsNullable=false)]
public List<FruitCrate> FruitCrate{
get {
return this.FruitCrate;
}
set {
this.FruitCrateField = value;
}
}
//soo on it's a large auto generated class