public IEnumerable <ValidationResult> Validate(ValidationContext validationContext) { var errors = new List <ValidationResult>(); if (string.IsNullOrWhiteSpace(MacAddress)) { errors.Add(new ValidationResult( errorMessage: "MAC-адрес не задан.", memberNames: new string[] { "macAddress" })); } else { if (MacAddress.IsValidMacAddress() == false) { errors.Add(new ValidationResult( errorMessage: "MAC-адрес некорректен.", memberNames: new string[] { "macAddress" })); } } if (string.IsNullOrWhiteSpace(IpAddress) == false) { if (IpAddress.IsValidIpAddress() == false) { errors.Add(new ValidationResult( errorMessage: "IP-адрес некорректен.", memberNames: new string[] { "ipAddress" })); } if (string.IsNullOrWhiteSpace(SubnetMask)) { errors.Add(new ValidationResult( errorMessage: "Маска подсети не задана.", memberNames: new string[] { "subnetMask" })); } else { if (SubnetMask.IsValidIpAddress() == false) { errors.Add(new ValidationResult( errorMessage: "Маска подсети некорректна.", memberNames: new string[] { "subnetMask" })); } } } else { if (string.IsNullOrWhiteSpace(SubnetMask) == false) { errors.Add(new ValidationResult( errorMessage: "IP-адрес не задан.", memberNames: new string[] { "ipAddress" })); if (SubnetMask.IsValidIpAddress() == false) { errors.Add(new ValidationResult( errorMessage: "Маска подсети некорректна.", memberNames: new string[] { "subnetMask" })); } } } return(errors); }