@@ -653,12 +653,12 @@ private void GenValidationAttributesClasses()
653653 OutCloseBrace ( ) ;
654654 }
655655
656- private void GenModelSelfValidationIfNecessary ( ValidatedModel modelToValidate , string modelName )
656+ private void GenModelSelfValidationIfNecessary ( ValidatedModel modelToValidate )
657657 {
658658 if ( modelToValidate . SelfValidates )
659659 {
660660 OutLn ( $ "context.MemberName = \" Validate\" ;") ;
661- OutLn ( $ "context.DisplayName = string.IsNullOrEmpty(name) ? \" { modelName } . Validate\" : $\" {{name}}.Validate\" ;") ;
661+ OutLn ( $ "context.DisplayName = string.IsNullOrEmpty(name) ? \" Validate\" : $\" {{name}}.Validate\" ;") ;
662662 OutLn ( $ "(builder ??= new()).AddResults(((global::System.ComponentModel.DataAnnotations.IValidatableObject)options).Validate(context));") ;
663663 OutLn ( ) ;
664664 }
@@ -693,8 +693,7 @@ private void GenModelValidationMethod(
693693 OutOpenBrace ( ) ;
694694 OutLn ( $ "global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null;") ;
695695 OutLn ( "#if NET10_0_OR_GREATER" ) ;
696- OutLn ( $ "string displayName = string.IsNullOrEmpty(name) ? \" { modelToValidate . SimpleName } .Validate\" : $\" {{name}}.Validate\" ;") ;
697- OutLn ( $ "var context = new { StaticValidationContextType } (options, displayName, null, null);") ;
696+ OutLn ( $ "var context = new { StaticValidationContextType } (options, \" { modelToValidate . SimpleName } \" , null, null);") ;
698697 OutLn ( "#else" ) ;
699698 OutLn ( $ "var context = new { StaticValidationContextType } (options);") ;
700699 OutLn ( "#endif" ) ;
@@ -712,33 +711,33 @@ private void GenModelValidationMethod(
712711 {
713712 if ( vm . ValidationAttributes . Count > 0 )
714713 {
715- GenMemberValidation ( vm , modelToValidate . SimpleName , ref staticValidationAttributesDict , cleanListsBeforeUse ) ;
714+ GenMemberValidation ( vm , ref staticValidationAttributesDict , cleanListsBeforeUse ) ;
716715 cleanListsBeforeUse = true ;
717716 OutLn ( ) ;
718717 }
719718
720719 if ( vm . TransValidatorType is not null )
721720 {
722- GenTransitiveValidation ( vm , modelToValidate . SimpleName , ref staticValidatorsDict ) ;
721+ GenTransitiveValidation ( vm , ref staticValidatorsDict ) ;
723722 OutLn ( ) ;
724723 }
725724
726725 if ( vm . EnumerationValidatorType is not null )
727726 {
728- GenEnumerationValidation ( vm , modelToValidate . SimpleName , ref staticValidatorsDict ) ;
727+ GenEnumerationValidation ( vm , ref staticValidatorsDict ) ;
729728 OutLn ( ) ;
730729 }
731730 }
732731
733- GenModelSelfValidationIfNecessary ( modelToValidate , modelToValidate . SimpleName ) ;
732+ GenModelSelfValidationIfNecessary ( modelToValidate ) ;
734733 OutLn ( $ "return builder is null ? global::Microsoft.Extensions.Options.ValidateOptionsResult.Success : builder.Build();") ;
735734 OutCloseBrace ( ) ;
736735 }
737736
738- private void GenMemberValidation ( ValidatedMember vm , string modelName , ref Dictionary < string , StaticFieldInfo > staticValidationAttributesDict , bool cleanListsBeforeUse )
737+ private void GenMemberValidation ( ValidatedMember vm , ref Dictionary < string , StaticFieldInfo > staticValidationAttributesDict , bool cleanListsBeforeUse )
739738 {
740739 OutLn ( $ "context.MemberName = \" { vm . Name } \" ;") ;
741- OutLn ( $ "context.DisplayName = string.IsNullOrEmpty(name) ? \" { modelName } . { vm . Name } \" : $\" {{name}}.{ vm . Name } \" ;") ;
740+ OutLn ( $ "context.DisplayName = string.IsNullOrEmpty(name) ? \" { vm . Name } \" : $\" {{name}}.{ vm . Name } \" ;") ;
742741
743742 if ( cleanListsBeforeUse )
744743 {
@@ -818,7 +817,7 @@ private StaticFieldInfo GetOrAddStaticValidationAttribute(ref Dictionary<string,
818817 return staticValidationAttributeInstance ;
819818 }
820819
821- private void GenTransitiveValidation ( ValidatedMember vm , string modelName , ref Dictionary < string , StaticFieldInfo > staticValidatorsDict )
820+ private void GenTransitiveValidation ( ValidatedMember vm , ref Dictionary < string , StaticFieldInfo > staticValidatorsDict )
822821 {
823822 string callSequence ;
824823 if ( vm . TransValidateTypeIsSynthetic )
@@ -834,7 +833,7 @@ private void GenTransitiveValidation(ValidatedMember vm, string modelName, ref D
834833
835834 var valueAccess = ( vm . IsNullable && vm . IsValueType ) ? ".Value" : string . Empty ;
836835
837- var baseName = $ "string.IsNullOrEmpty(name) ? \" { modelName } . { vm . Name } \" : $\" {{name}}.{ vm . Name } \" ";
836+ var baseName = $ "string.IsNullOrEmpty(name) ? \" { vm . Name } \" : $\" {{name}}.{ vm . Name } \" ";
838837
839838 if ( vm . IsNullable )
840839 {
@@ -849,7 +848,7 @@ private void GenTransitiveValidation(ValidatedMember vm, string modelName, ref D
849848 }
850849 }
851850
852- private void GenEnumerationValidation ( ValidatedMember vm , string modelName , ref Dictionary < string , StaticFieldInfo > staticValidatorsDict )
851+ private void GenEnumerationValidation ( ValidatedMember vm , ref Dictionary < string , StaticFieldInfo > staticValidatorsDict )
853852 {
854853 var valueAccess = ( vm . IsValueType && vm . IsNullable ) ? ".Value" : string . Empty ;
855854 var enumeratedValueAccess = ( vm . EnumeratedIsNullable && vm . EnumeratedIsValueType ) ? ".Value" : string . Empty ;
@@ -880,15 +879,15 @@ private void GenEnumerationValidation(ValidatedMember vm, string modelName, ref
880879 {
881880 OutLn ( $ "if (o is not null)") ;
882881 OutOpenBrace ( ) ;
883- var propertyName = $ "string.IsNullOrEmpty(name) ? $\" { modelName } . { vm . Name } [{{count}}]\" : $\" {{name}}.{ vm . Name } [{{count}}]\" ";
882+ var propertyName = $ "string.IsNullOrEmpty(name) ? $\" { vm . Name } [{{count}}]\" : $\" {{name}}.{ vm . Name } [{{count}}]\" ";
884883 OutLn ( $ "(builder ??= new()).AddResult({ callSequence } .Validate({ propertyName } , o{ enumeratedValueAccess } ));") ;
885884 OutCloseBrace ( ) ;
886885
887886 if ( ! vm . EnumeratedMayBeNull )
888887 {
889888 OutLn ( $ "else") ;
890889 OutOpenBrace ( ) ;
891- var error = $ "string.IsNullOrEmpty(name) ? $\" { modelName } . { vm . Name } [{{count}}] is null\" : $\" {{name}}.{ vm . Name } [{{count}}] is null\" ";
890+ var error = $ "string.IsNullOrEmpty(name) ? $\" { vm . Name } [{{count}}] is null\" : $\" {{name}}.{ vm . Name } [{{count}}] is null\" ";
892891 OutLn ( $ "(builder ??= new()).AddError({ error } );") ;
893892 OutCloseBrace ( ) ;
894893 }
@@ -897,7 +896,7 @@ private void GenEnumerationValidation(ValidatedMember vm, string modelName, ref
897896 }
898897 else
899898 {
900- var propertyName = $ "string.IsNullOrEmpty(name) ? $\" { modelName } . { vm . Name } [{{count++}}] is null \" : $\" {{name}}.{ vm . Name } [{{count++}}] is null \" ";
899+ var propertyName = $ "string.IsNullOrEmpty(name) ? $\" { vm . Name } [{{count++}}]\" : $\" {{name}}.{ vm . Name } [{{count++}}]\" ";
901900 OutLn ( $ "(builder ??= new()).AddResult({ callSequence } .Validate({ propertyName } , o{ enumeratedValueAccess } ));") ;
902901 }
903902
0 commit comments