I tried to reorganize this
class AClass { string Property1 { get; set; } string Property2 { get; set; } string Property3 { get; set; } void AMethod(AClass other) { if(String.IsNullOrEmpty(this.Property1)) { this.Property1 = other.Property1; } if(String.IsNullOrEmpty(this.Property2)) { this.Property2 = other.Property2; } if(String.IsNullOrEmpty(this.Property3)) { this.Property3 = other.Property3; } } }
And the only thing I could come up with was
private string GetFirstNotNullOrEmpty(string first, string second) { if (String.IsNullOrEmpty(first)) { return second; } return first; }
and
this.Property1 = GetFirstNotNullOrEmpty(this.Property1, other.Property1);
This is not entirely equivalent, but will do the job. Is there a better way to reorganize this?
source share