@@ -159,6 +159,11 @@ public bool TryGetValidatableTypeInfo(global::System.Type type, [global::System.
159
159
validatableInfo = CreateExecuteOptions ( ) ;
160
160
return true ;
161
161
}
162
+ if ( type == typeof ( global ::Microsoft . Diagnostics . Tools . Monitor . AzureAdOptions ) )
163
+ {
164
+ validatableInfo = CreateAzureAdOptions ( ) ;
165
+ return true ;
166
+ }
162
167
if ( type == typeof ( global ::TestValidatableType ) )
163
168
{
164
169
validatableInfo = CreateTestValidatableType ( ) ;
@@ -688,12 +693,6 @@ private ValidatableTypeInfo CreateBaseRecordOptions()
688
693
return new GeneratedValidatableTypeInfo (
689
694
type : typeof ( global ::Microsoft . Diagnostics . Tools . Monitor . CollectionRules . Options . Actions . BaseRecordOptions ) ,
690
695
members : [
691
- // new GeneratedValidatablePropertyInfo(
692
- // containingType: typeof(global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Actions.BaseRecordOptions),
693
- // propertyType: typeof(global::System.Type),
694
- // name: "EqualityContract",
695
- // displayName: "EqualityContract"
696
- // ),
697
696
]
698
697
) ;
699
698
}
@@ -702,12 +701,6 @@ private ValidatableTypeInfo CreateExecuteOptions()
702
701
return new GeneratedValidatableTypeInfo (
703
702
type : typeof ( global ::Microsoft . Diagnostics . Tools . Monitor . CollectionRules . Options . Actions . ExecuteOptions ) ,
704
703
members : [
705
- // new GeneratedValidatablePropertyInfo(
706
- // containingType: typeof(global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Actions.ExecuteOptions),
707
- // propertyType: typeof(global::System.Type),
708
- // name: "EqualityContract",
709
- // displayName: "EqualityContract"
710
- // ),
711
704
new GeneratedValidatablePropertyInfo (
712
705
containingType : typeof ( global ::Microsoft . Diagnostics . Tools . Monitor . CollectionRules . Options . Actions . ExecuteOptions ) ,
713
706
propertyType : typeof ( string ) ,
@@ -717,6 +710,38 @@ private ValidatableTypeInfo CreateExecuteOptions()
717
710
]
718
711
) ;
719
712
}
713
+ private ValidatableTypeInfo CreateAzureAdOptions ( )
714
+ {
715
+ return new GeneratedValidatableTypeInfo (
716
+ type : typeof ( global ::Microsoft . Diagnostics . Tools . Monitor . AzureAdOptions ) ,
717
+ members : [
718
+ new GeneratedValidatablePropertyInfo (
719
+ containingType : typeof ( global ::Microsoft . Diagnostics . Tools . Monitor . AzureAdOptions ) ,
720
+ propertyType : typeof ( string ) ,
721
+ name : "TenantId" ,
722
+ displayName : "TenantId"
723
+ ) ,
724
+ new GeneratedValidatablePropertyInfo (
725
+ containingType : typeof ( global ::Microsoft . Diagnostics . Tools . Monitor . AzureAdOptions ) ,
726
+ propertyType : typeof ( string ) ,
727
+ name : "ClientId" ,
728
+ displayName : "ClientId"
729
+ ) ,
730
+ new GeneratedValidatablePropertyInfo (
731
+ containingType : typeof ( global ::Microsoft . Diagnostics . Tools . Monitor . AzureAdOptions ) ,
732
+ propertyType : typeof ( global ::System . Uri ) ,
733
+ name : "AppIdUri" ,
734
+ displayName : "AppIdUri"
735
+ ) ,
736
+ new GeneratedValidatablePropertyInfo (
737
+ containingType : typeof ( global ::Microsoft . Diagnostics . Tools . Monitor . AzureAdOptions ) ,
738
+ propertyType : typeof ( string ) ,
739
+ name : "RequiredRole" ,
740
+ displayName : "RequiredRole"
741
+ ) ,
742
+ ]
743
+ ) ;
744
+ }
720
745
private ValidatableTypeInfo CreateTestValidatableType ( )
721
746
{
722
747
return new GeneratedValidatableTypeInfo (
@@ -740,6 +765,12 @@ private ValidatableTypeInfo CreateTestValidatableType()
740
765
name : "ExecuteOptions" ,
741
766
displayName : "ExecuteOptions"
742
767
) ,
768
+ new GeneratedValidatablePropertyInfo (
769
+ containingType : typeof ( global ::TestValidatableType ) ,
770
+ propertyType : typeof ( global ::Microsoft . Diagnostics . Tools . Monitor . AzureAdOptions ) ,
771
+ name : "AzureAdOptions" ,
772
+ displayName : "AzureAdOptions"
773
+ ) ,
743
774
]
744
775
) ;
745
776
}
@@ -749,8 +780,8 @@ private ValidatableTypeInfo CreateTestValidatableType()
749
780
[ global ::System . CodeDom . Compiler . GeneratedCodeAttribute ( "Microsoft.AspNetCore.Http.ValidationsGenerator, Version=10.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60" , "10.0.0.0" ) ]
750
781
internal static class GeneratedServiceCollectionExtensions
751
782
{
752
- // [global::System.Runtime.CompilerServices.InterceptsLocationAttribute(1, "nMLdYxVpxyjXwof6UabUh7sBAABQcm9ncmFtLmNz ")]
753
- public static global ::Microsoft . Extensions . DependencyInjection . IServiceCollection AddValidation ( this global ::Microsoft . Extensions . DependencyInjection . IServiceCollection services , global ::System . Action < ValidationOptions > ? configureOptions = null )
783
+ // [global::System.Runtime.CompilerServices.InterceptsLocationAttribute(1, "/S4C/fYaYK+RGue0pzw4eqSWAABWYWxpZGF0YWJsZUluZm9SZXNvbHZlci5jcw== ")]
784
+ public static global ::Microsoft . Extensions . DependencyInjection . IServiceCollection AddValidation ( this global ::Microsoft . Extensions . DependencyInjection . IServiceCollection services , global ::System . Action < global :: Microsoft . AspNetCore . Http . Validation . ValidationOptions > ? configureOptions = null )
754
785
{
755
786
// Use non-extension method to avoid infinite recursion.
756
787
return global ::Microsoft . Extensions . DependencyInjection . ValidationServiceCollectionExtensions . AddValidation ( services , options =>
@@ -777,13 +808,39 @@ private sealed record CacheKey(global::System.Type ContainingType, string Proper
777
808
var key = new CacheKey ( containingType , propertyName ) ;
778
809
return _cache . GetOrAdd ( key , static k =>
779
810
{
811
+ var results = new global ::System . Collections . Generic . List < global ::System . ComponentModel . DataAnnotations . ValidationAttribute > ( ) ;
812
+
813
+ // Get attributes from the property
780
814
var property = k . ContainingType . GetProperty ( k . PropertyName ) ;
781
- if ( property = = null )
815
+ if ( property ! = null )
782
816
{
783
- return [ ] ;
817
+ var propertyAttributes = global ::System . Reflection . CustomAttributeExtensions
818
+ . GetCustomAttributes < global ::System . ComponentModel . DataAnnotations . ValidationAttribute > ( property , inherit : true ) ;
819
+
820
+ results . AddRange ( propertyAttributes ) ;
821
+ }
822
+
823
+ // Check constructors for parameters that match the property name
824
+ // to handle record scenarios
825
+ foreach ( var constructor in k . ContainingType . GetConstructors ( ) )
826
+ {
827
+ // Look for parameter with matching name (case insensitive)
828
+ var parameter = global ::System . Linq . Enumerable . FirstOrDefault (
829
+ constructor . GetParameters ( ) ,
830
+ p => string . Equals ( p . Name , k . PropertyName , global ::System . StringComparison . OrdinalIgnoreCase ) ) ;
831
+
832
+ if ( parameter != null )
833
+ {
834
+ var paramAttributes = global ::System . Reflection . CustomAttributeExtensions
835
+ . GetCustomAttributes < global ::System . ComponentModel . DataAnnotations . ValidationAttribute > ( parameter , inherit : true ) ;
836
+
837
+ results . AddRange ( paramAttributes ) ;
838
+
839
+ break ;
840
+ }
784
841
}
785
842
786
- return [ .. global :: System . Reflection . CustomAttributeExtensions . GetCustomAttributes < global :: System . ComponentModel . DataAnnotations . ValidationAttribute > ( property , inherit : true ) ] ;
843
+ return results . ToArray ( ) ;
787
844
} ) ;
788
845
}
789
846
}
0 commit comments