c# - Validating inherited attribute using DataAnnotations -


i have mvc project relies on webservices provide data , webservices based on cmis specification custom functionality. have several classes used datacontracts, created visual studio when added references services calling. using class model ensure able send instances service , process correctly sent me.

i have views edit instances of classes , use dataannotations validate forms (usually [required] atribute , display name change).

i not want put atributes in service reference files because updating reference mean loose atributes (at least not sure still same after reference update).

my thought create child class serve tool introduce dataannotations atributes know sure using (those not dissapear datacontract class sure). how accomplish such inheritance code?

example - have class created vs in reference.cs file:

[system.diagnostics.debuggerstepthroughattribute()] [system.codedom.compiler.generatedcodeattribute("system.runtime.serialization", "4.0.0.0")] [system.runtime.serialization.datacontractattribute(name="libraryrequest", namespace="http://schemas.datacontract.org/2004/07/agamemnon.models")] [system.serializableattribute()] public partial class libraryrequest : doculive.repositoryserviceext.library {      [system.runtime.serialization.optionalfieldattribute()]     private string passwordfield;      [system.runtime.serialization.optionalfieldattribute()]     private string serverfield;      [system.runtime.serialization.optionalfieldattribute()]     private bool usedefaultfield;      [system.runtime.serialization.optionalfieldattribute()]     private string usernamefield;      [system.runtime.serialization.datamemberattribute()]     public string password {         {             return this.passwordfield;         }         set {             if ((object.referenceequals(this.passwordfield, value) != true)) {                 this.passwordfield = value;                 this.raisepropertychanged("password");             }         }     }      [system.runtime.serialization.datamemberattribute()]     public string server {         {             return this.serverfield;         }         set {             if ((object.referenceequals(this.serverfield, value) != true)) {                 this.serverfield = value;                 this.raisepropertychanged("server");             }         }     }      [system.runtime.serialization.datamemberattribute()]     public bool usedefault {         {             return this.usedefaultfield;         }         set {             if ((this.usedefaultfield.equals(value) != true)) {                 this.usedefaultfield = value;                 this.raisepropertychanged("usedefault");             }         }     }      [system.runtime.serialization.datamemberattribute()]     public string username {         {             return this.usernamefield;         }         set {             if ((object.referenceequals(this.usernamefield, value) != true)) {                 this.usernamefield = value;                 this.raisepropertychanged("username");             }         }     } } 

i want make sure no matter changes in reference.cs file (even class itself), have username, password , server marked [required] in "edit" , "delete" forms.

thanks in advance

honza

i stay away inheriting autogenerated class. not solve problem attributes - have override every single property can add attributes it.

one solution use hand-coded datacontracts instead of autogenerated references. have full control on when change, , can put attributes need in them.

another solution wrapping contract in view model. this:

 public class libraryrequestviewmodel  {      private libraryrequest request;       public libraryrequestviewmodel(libraryrequest request){           this.request = request;      }       [required]      public string password {          { return this.request.password; }          set { this.request.password = value; }      }      // fields need   } 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -