An easy way to validate an XML against a C# Class -


i use xml format keep settings c# project. theses xmls deserialized c# classes.

often enough, class design changes forget update xml. deserialization works fine , missing elements default values.

this behavior not desirable me. i have automatic validation asserts class , xml have same structure.

i know can create xml schemas (e.g using xsd) classes, not figure easy way automatically , not manually (recall classes' design changes often). also, solution seems kind of unnatural. not need xml schemas. have classes , serialized xml instances. adding schemas seems superfluous.

thanks bunch.

why don't create method in settings class can invoked after xml deserialization?

suppose have class this:

class settings {     public string property1 { get; set; }     public int property2 { get; set; }      public bool isvalid() {         if(string.isnullorempty(property1)) return false;         if(property2 == 0) return false;     } } 

using isvalid can check in class. please, remember example. think manage object validation. if change in time, can edit validation method check new situations.


Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -