I have a fairly simple object:
public class Person
{
public string FirstName { get; set; }
public string LastName { get; set; }
public Address MailingAddress { get; set; }
}
Where Address is defined like so:
public class Address
{
public string StreetAddress { get; set; }
public string PostalCode { get; set; }
public string Province { get; set; }
public string PostalCode { get; set; }
}
Now, I'm binding my UI as shown
here, and my IDataErrorInfo looks like this:
public string this[string columnName]
{
get
{
string result = null;
// the following works fine
if(columnName == "FirstName")
{
if (string.IsNullOrEmpty(this.FirstName))
result = "First name cannot be blank.";
}
// the following does not run
// mostly because I don't know what the columnName should be
else if (columnName == "NotSureWhatToPutHere")
{
if (!Util.IsValidPostalCode(this.MailingAddress.PostalCode))
result = "Postal code is not in a know format.";
}
return result;
}
}
So, obviously, I don't know what the columnName should be. I've tried "MailingAddress.PostalCode" and I've even tried running something like if (columnName.ToUpperInvariant().Contains("POSTAL")) System.Windows.Forms.MessageBox.Show("Validating Postal Code"); but to no avail.
Can I not validate complex or aggregate types via IDataErrorInfo, or is there something I'm missing?