나는 약 40 개의 속성을 가진 클래스가있다. (나는 이것에 대해 말하지 않는다. 스펙대로이다.) 모든 속성에는 사용자 지정 "set"메서드가 있습니다.이 코드 블록을 다시 쓰는 방법은 무엇입니까?
모든 "설정"방법에 대해 약간의 복잡한 검증이 필요합니다. 이미 유효성 검사를 별도의 방법으로 분리했습니다.
CommonValidate(string PropertyName, string PropertyValue)
으로 전화를 걸 수 있습니다.
public string Property1
{
set
{
this.field1 = value;
CommonValidate(Property1, this.field1);
}
}
public DateTime Property2
{
set
{
this.field2 = value.ToString("ddMMyy");;
CommonValidate(Property2, this.field2);
}
}
public string Property3
{
set
{
this.field3 = value;
CommonValidate(Property3, this.field3);
}
}
난 그냥 모든 (40)이 방법을 "설정"에서 호출 CommonValidate 방법을 붙여 넣은이 방법을 : 나는 각에서이 검증 메소드를 호출하고 지금부터 당신이 아래에 볼 수
는 방법을 "설정" . 이 방법은 매우 효과적이지 않습니다. CommonValidate 메소드의 인수 개수에 대한 변경 요청이 있는지 상상해보십시오.
더 나은 모드로 변경할 수있는 다른 방법이 있습니까?
http://codereview.stackexchange.com/ – wudzik
이것은 codereview 질문이 아닙니다. –
CommonValidate에 "this"만 전달합니까? –