次のように単純に定義された Address オブジェクトがあります。
public class Address
{
public string StreetNumber { get; set; }
public string StreetAddress { get; set; }
public string City { get; set; }
public string PostalCode { get; set; }
}
かなり単純です。私が尋ねた別の質問へのアドバイスとして、UI を Person 型のオブジェクト (Address MailingAddress フィールドを含む) にデータバインドするときに、このブログ投稿を参照しています。
問題は、IDataError インターフェイス メソッドが Address 型のプロパティを検証していないことです。
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;
}
}
だから、明らかに私は columnName がどうなるか分かりません...私はそれを一歩踏み出しましたが、それは(組み込み型の)パブリックプロパティ以外のものではありませんでした。次のようなステートメントを実行して中断しようとしました。
if (columnName.Contains("Mailing") || columnName.Contains("Postal"))
System.Windows.Forms.MessageBox.Show(columnName);
すべて役に立たない。
足りないものはありますか?