我有 A、B、C 类:
public class A
{
public int Prop1;
public int Prop2;
public int Prop3;
public int Prop4;
public int Prop5;
}
public class B:A
{
public int PropB1;
public int PropB2;
}
public class C:A
{
public int PropC1;
}
我从可用变量创建对象 B、C:
var b = new B
{
Prop1 = param1,
Prop2 = param2,
Prop3 = param3,
Prop4 = param4,
Prop5 = param5,
PropB1 = param6,
PropB2 = param7,
}
var c = new C
{
Prop1 = param1,
Prop2 = param2,
Prop3 = param3,
Prop4 = param4,
Prop5 = param5,
PropC1 = param8
}
使用这种编码风格,它有重复的代码。如何避免这种情况。请帮我。谢谢。
Prop1 = param1, Prop2 = param2, Prop3 = param3, Prop4 = param4, Prop5 = param5,
谢谢。