2011-02-10 4 views
0

私は抽象クラスを持っています。これは、あるインタフェースからプロパティを継承しています。したがって、プロパティのバッキングフィールドを検証することは不可能です。プロパティを検証するためにカスタム属性を実装する方法はありますか?バリデーション属性

あなたは抽象クラスコラボレーターを得た、

public abstract class Collaborator 
{ 
} 

は、その後、あなたは、いくつかのインターフェイスからそれを継承する:

interface IPersonInformation 
{ 
    String FirstName { get; set; } 
    String LastName { get; set; } 
} 
interface IRecruitmentInformation 
{ 
    DateTime RecruitmentDate { get; set; } 
} 
/// 
public abstract class Collaborator : IPersonInformation, IRecruitmentInformation 
{ 
    public String FirstName { get; set; } 
    public String LastName { get; set; } 
    public DateTime RecruitmentDate { get; set; } 
} 

だから、彼らのバッキングフィールドを使用してCollaboratorクラスのプロパティを検証することはできません - 彼らは自動的に行われます。 プロパティの属性を使用して名前を検証する方法はありますか?

+0

あなたの質問は不明です。サンプルコードを提供できますか? –

+0

自動実装のプロパティを使用する必要はありません。とにかく、検証属性(PostSharp、ValidationManager)を使用することができます。 –

答えて

0
public abstract class Collaborator : IPersonInformation, IRecruitmentInformation 
{ 
    private string firstName; 
    public String FirstName 
    { 
     get { return firstName; } 
     set 
     { 

      //validation code 

      this.firstName = value; 
     } 
    } 
    public String LastName { get; set; } 
    public DateTime RecruitmentDate { get; set; } 
} 

インターフェイスを実装する方法としては問題ありません。私は属性を使ってこれを達成するより良い方法を考えることができません。

関連する問題