diff --git a/XmlSchemaClassGenerator/TypeModel.cs b/XmlSchemaClassGenerator/TypeModel.cs index 961d0c16..f8681a97 100644 --- a/XmlSchemaClassGenerator/TypeModel.cs +++ b/XmlSchemaClassGenerator/TypeModel.cs @@ -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] >(