mamift / LinqToXsdCore

LinqToXsd ported to .NET Core (targets .NET Standard 2 for generated code and .NET Core 3.1, .NET 5+ for the code generator CLI tool).
Microsoft Public License
44 stars 15 forks source link

Support DataAnnotations? #66

Closed jhancock-taxa closed 4 months ago

jhancock-taxa commented 5 months ago

I searched everywhere and I couldn't find any documentation on how to enable DataAnnotations being generated on the file. It see that it's generating XML Documentation but not generating DataAnnotations.

I was expecting like the xsd.exe to see MaxLength, RegularExpression, Description attributes on everything.

Is there a way to turn these on?

mamift commented 5 months ago

Sorry but LinqToXsd does not support those. It was originally started as a strongly-typed wrapper API around the Linq to XML API (think XDocument, XElement etc), and it's evolved that way. Adding that in is definitely possible though, but the code generator does not generate these attributes at the moment.

mamift commented 5 months ago

If System.Component.DataAnnotations are a hard requirement, I recommend using XmlSchemaClassGenerator - it generates code that's very close to what old-school xsd.exe gives you and also supports emitting DataAnnotations. LinqToXSD has its own validation mechanism that does not use DataAnnotations (it generates its own TypeValidator classes for validation).