Method overrides cannot add preconditions.


hi
i've read thread on derived classes , have question
have abstract class hasn't property i've in derived class.
want use require contract on property.
how think implement this?

examle:
public abstract class  {       public abstract void methoda  }    public class b :  {      public dattime isa{get;set;}      public override void methoda()      {          contract.require(isa!=null);      }  }

hi,

alternatively, create abstraction preconditions moving them pure abstract method.  example:

(note: haven't tried compiling code)

[contractclass(typeof(acontracts))]  public abstract class  {      [pure]      protected abstract bool methodacanexecute();      public abstract void methoda();  }    [contractclassfor(typeof(a))]  public abstract class acontracts :  {     protected override abstract bool methodacanexecute();     public override void methoda()     {        contract.requires(methodacanexecute());     }  }    public class b :  {      public string isa { get; set; }      protected override bool methodacanexecute()      {          return isa != null;      }      public override void methoda()      {          // no additional preconditions necessary      }  }  


- dave


DevLabs  >  Code Contracts



Comments

Popular posts from this blog

Azure DocumentDB Owner resource does not exist

BizTalk Server 2013 Azure VM Log Shipping and HA for hosts

How to Share webservice object to all user