Search code examples
.netxmlvisual-studionhibernatehbm

XML code analysis like Roslyn for Visual Studio


Is there a way to enforce set of rules on xml file included in .NET project?

In my case I would like to throw compiler error if some settings are not set in hbm.xml file (nHibernate mapping).

I know about xsd files, but I would need to do an overriding of existing nHibernate schema, which in its current form is complicated (it requires xml 1.1).

[Edit]:
To be specific: I want to define a rule that gives a compilation error, when an nhibernate hbm file doesn't contain specific property set (dynamic-update="true").


Solution

  • Another option is to write unit tests loads the XML files and performs the checks you want. They could look at classes too, perhaps using reflection to automatically applythe same checks to new classes.