構造函數難題,我有這兩個構造函數。一個是製作該類的副本,另一個是標準構造函數。我需要調用第一個,以便我可以在其中使用規則。我不應該重複代碼,所以我正在尋找一種避免覆蓋這兩個維度的方法。複製構造函數去基礎構造函數並覆蓋複製值
public SprinklerLineModel()
{
NearCrossMainDimension = new PipeDimensionModel();
FarCrossMainDimension = new PipeDimensionModel();
this.AddValidationRule(Rule.CreateRule(() => BranchLineDiameter, RuleMessage.GREATER_THAN_ZERO,() => BranchLineDiameter > 0));
}
/// <summary>
/// Copy Constructor
/// </summary>
/// <param name="sprinklerLineModel">Original copy of sprinklerLineModel</param>
public SprinklerLineModel(SprinklerLineModel sprinklerLineModel)
:this()
{
this.EstimatedFlow = sprinklerLineModel.EstimatedFlow;
this.EstimatedPressure = sprinklerLineModel.EstimatedPressure;
this.NearCrossMainDimension = new PipeDimensionModel(sprinklerLineModel.NearCrossMainDimension);
this.FarCrossMainDimension = new PipeDimensionModel(sprinklerLineModel.FarCrossMainDimension);
this.BranchLineDiameter = sprinklerLineModel.BranchLineDiameter;
this.LeadLinePipeFittingLength = sprinklerLineModel.LeadLinePipeFittingLength;
this.ExbPipeFittingLength = sprinklerLineModel.ExbPipeFittingLength;
this.IsDirty = sprinklerLineModel.IsDirty;
}
我想能夠調用默認的構造函數而不覆蓋這兩個變量。任何幫助,將不勝感激。
我想我可以檢查一下,看看它們是否爲空,但看起來好像不是最好的方法。
感謝