Skip to content

Commit

Permalink
Add RequiredAttribute when use="required" (fixes #212)
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Ganss committed Jun 19, 2020
1 parent 257e5b7 commit 3b2392c
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions XmlSchemaClassGenerator/TypeModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -935,6 +935,12 @@ public void AddMembersTo(CodeTypeDeclaration typeDeclaration, bool withDataBindi

AddDocs(member);

if (!IsNullable && Configuration.DataAnnotationMode != DataAnnotationMode.None)
{
var requiredAttribute = new CodeAttributeDeclaration(new CodeTypeReference(typeof(RequiredAttribute), Configuration.CodeTypeReferenceOptions));
member.CustomAttributes.Add(requiredAttribute);
}

if (IsDeprecated)
{
// From .NET 3.5 XmlSerializer doesn't serialize objects with [Obsolete] >(
Expand Down

0 comments on commit 3b2392c

Please sign in to comment.