1+ //HintName: ValidatableInfoResolver.g.cs
2+ #nullable enable annotations
3+ //------------------------------------------------------------------------------
4+ // <auto-generated>
5+ // This code was generated by a tool.
6+ //
7+ // Changes to this file may cause incorrect behavior and will be lost if
8+ // the code is regenerated.
9+ // </auto-generated>
10+ //------------------------------------------------------------------------------
11+ #nullable enable
12+ #pragma warning disable ASP0029
13+
14+ namespace System . Runtime . CompilerServices
15+ {
16+ [ global ::System . CodeDom . Compiler . GeneratedCodeAttribute ( "Microsoft.Extensions.Validation.ValidationsGenerator, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60" , "42.42.42.42" ) ]
17+ [ AttributeUsage ( AttributeTargets . Method , AllowMultiple = true ) ]
18+ file sealed class InterceptsLocationAttribute : System . Attribute
19+ {
20+ public InterceptsLocationAttribute ( int version , string data )
21+ {
22+ }
23+ }
24+ }
25+
26+ namespace Microsoft . Extensions . Validation . Generated
27+ {
28+ [ global ::System . CodeDom . Compiler . GeneratedCodeAttribute ( "Microsoft.Extensions.Validation.ValidationsGenerator, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60" , "42.42.42.42" ) ]
29+ file sealed class GeneratedValidatablePropertyInfo : global ::Microsoft . Extensions . Validation . ValidatablePropertyInfo
30+ {
31+ public GeneratedValidatablePropertyInfo (
32+ [ param: global ::System . Diagnostics . CodeAnalysis . DynamicallyAccessedMembers ( global ::System . Diagnostics . CodeAnalysis . DynamicallyAccessedMemberTypes . PublicProperties | global ::System . Diagnostics . CodeAnalysis . DynamicallyAccessedMemberTypes . PublicConstructors ) ]
33+ global ::System . Type containingType ,
34+ global ::System . Type propertyType ,
35+ string name ,
36+ string displayName ) : base ( containingType , propertyType , name , displayName )
37+ {
38+ ContainingType = containingType ;
39+ Name = name ;
40+ }
41+
42+ [ global ::System . Diagnostics . CodeAnalysis . DynamicallyAccessedMembers ( global ::System . Diagnostics . CodeAnalysis . DynamicallyAccessedMemberTypes . PublicProperties | global ::System . Diagnostics . CodeAnalysis . DynamicallyAccessedMemberTypes . PublicConstructors ) ]
43+ internal global ::System . Type ContainingType { get ; }
44+ internal string Name { get ; }
45+
46+ protected override global ::System . ComponentModel . DataAnnotations . ValidationAttribute [ ] GetValidationAttributes ( )
47+ => ValidationAttributeCache . GetValidationAttributes ( ContainingType , Name ) ;
48+ }
49+
50+ [ global ::System . CodeDom . Compiler . GeneratedCodeAttribute ( "Microsoft.Extensions.Validation.ValidationsGenerator, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60" , "42.42.42.42" ) ]
51+ file sealed class GeneratedValidatableTypeInfo : global ::Microsoft . Extensions . Validation . ValidatableTypeInfo
52+ {
53+ public GeneratedValidatableTypeInfo (
54+ [ param: global ::System . Diagnostics . CodeAnalysis . DynamicallyAccessedMembers ( global ::System . Diagnostics . CodeAnalysis . DynamicallyAccessedMemberTypes . Interfaces ) ]
55+ global ::System . Type type ,
56+ ValidatablePropertyInfo [ ] members ) : base ( type , members ) { }
57+ }
58+
59+ [ global ::System . CodeDom . Compiler . GeneratedCodeAttribute ( "Microsoft.Extensions.Validation.ValidationsGenerator, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60" , "42.42.42.42" ) ]
60+ file class GeneratedValidatableInfoResolver : global ::Microsoft . Extensions . Validation . IValidatableInfoResolver
61+ {
62+ public bool TryGetValidatableTypeInfo ( global ::System . Type type , [ global ::System . Diagnostics . CodeAnalysis . NotNullWhen ( true ) ] out global ::Microsoft . Extensions . Validation . IValidatableInfo ? validatableInfo )
63+ {
64+ validatableInfo = null ;
65+ if ( type == typeof ( global ::ComplexTypeWithJsonIgnore ) )
66+ {
67+ validatableInfo = new GeneratedValidatableTypeInfo (
68+ type : typeof ( global ::ComplexTypeWithJsonIgnore ) ,
69+ members : [
70+ new GeneratedValidatablePropertyInfo (
71+ containingType : typeof ( global ::ComplexTypeWithJsonIgnore ) ,
72+ propertyType : typeof ( int ) ,
73+ name : "ValidatedProperty" ,
74+ displayName : "ValidatedProperty"
75+ ) ,
76+ ]
77+ ) ;
78+ return true ;
79+ }
80+
81+ return false ;
82+ }
83+
84+ // No-ops, rely on runtime code for ParameterInfo-based resolution
85+ public bool TryGetValidatableParameterInfo ( global ::System . Reflection . ParameterInfo parameterInfo , [ global ::System . Diagnostics . CodeAnalysis . NotNullWhen ( true ) ] out global ::Microsoft . Extensions . Validation . IValidatableInfo ? validatableInfo )
86+ {
87+ validatableInfo = null ;
88+ return false ;
89+ }
90+ }
91+
92+ [ global ::System . CodeDom . Compiler . GeneratedCodeAttribute ( "Microsoft.Extensions.Validation.ValidationsGenerator, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60" , "42.42.42.42" ) ]
93+ file static class GeneratedServiceCollectionExtensions
94+ {
95+ [ InterceptsLocation ]
96+ public static global ::Microsoft . Extensions . DependencyInjection . IServiceCollection AddValidation ( this global ::Microsoft . Extensions . DependencyInjection . IServiceCollection services , global ::System . Action < global ::Microsoft . Extensions . Validation . ValidationOptions > ? configureOptions = null )
97+ {
98+ // Use non-extension method to avoid infinite recursion.
99+ return global ::Microsoft . Extensions . DependencyInjection . ValidationServiceCollectionExtensions . AddValidation ( services , options =>
100+ {
101+ options . Resolvers . Insert ( 0 , new GeneratedValidatableInfoResolver ( ) ) ;
102+ if ( configureOptions is not null )
103+ {
104+ configureOptions ( options ) ;
105+ }
106+ } ) ;
107+ }
108+ }
109+
110+ [ global ::System . CodeDom . Compiler . GeneratedCodeAttribute ( "Microsoft.Extensions.Validation.ValidationsGenerator, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60" , "42.42.42.42" ) ]
111+ file static class ValidationAttributeCache
112+ {
113+ private sealed record CacheKey (
114+ [ param: global ::System . Diagnostics . CodeAnalysis . DynamicallyAccessedMembers ( global ::System . Diagnostics . CodeAnalysis . DynamicallyAccessedMemberTypes . PublicProperties | global ::System . Diagnostics . CodeAnalysis . DynamicallyAccessedMemberTypes . PublicConstructors ) ]
115+ [ property: global ::System . Diagnostics . CodeAnalysis . DynamicallyAccessedMembers ( global ::System . Diagnostics . CodeAnalysis . DynamicallyAccessedMemberTypes . PublicProperties | global ::System . Diagnostics . CodeAnalysis . DynamicallyAccessedMemberTypes . PublicConstructors ) ]
116+ global ::System . Type ContainingType ,
117+ string PropertyName ) ;
118+ private static readonly global ::System . Collections . Concurrent . ConcurrentDictionary < CacheKey , global ::System . ComponentModel . DataAnnotations . ValidationAttribute [ ] > _cache = new ( ) ;
119+
120+ public static global ::System . ComponentModel . DataAnnotations . ValidationAttribute [ ] GetValidationAttributes (
121+ [ global ::System . Diagnostics . CodeAnalysis . DynamicallyAccessedMembers ( global ::System . Diagnostics . CodeAnalysis . DynamicallyAccessedMemberTypes . PublicProperties | global ::System . Diagnostics . CodeAnalysis . DynamicallyAccessedMemberTypes . PublicConstructors ) ]
122+ global ::System . Type containingType ,
123+ string propertyName )
124+ {
125+ var key = new CacheKey ( containingType , propertyName ) ;
126+ return _cache . GetOrAdd ( key , static k =>
127+ {
128+ var results = new global ::System . Collections . Generic . List < global ::System . ComponentModel . DataAnnotations . ValidationAttribute > ( ) ;
129+
130+ // Get attributes from the property
131+ var property = k . ContainingType . GetProperty ( k . PropertyName ) ;
132+ if ( property != null )
133+ {
134+ var propertyAttributes = global ::System . Reflection . CustomAttributeExtensions
135+ . GetCustomAttributes < global ::System . ComponentModel . DataAnnotations . ValidationAttribute > ( property , inherit : true ) ;
136+
137+ results . AddRange ( propertyAttributes ) ;
138+ }
139+
140+ // Check constructors for parameters that match the property name
141+ // to handle record scenarios
142+ foreach ( var constructor in k . ContainingType . GetConstructors ( ) )
143+ {
144+ // Look for parameter with matching name (case insensitive)
145+ var parameter = global ::System . Linq . Enumerable . FirstOrDefault (
146+ constructor . GetParameters ( ) ,
147+ p => string . Equals ( p . Name , k . PropertyName , global ::System . StringComparison . OrdinalIgnoreCase ) ) ;
148+
149+ if ( parameter != null )
150+ {
151+ var paramAttributes = global ::System . Reflection . CustomAttributeExtensions
152+ . GetCustomAttributes < global ::System . ComponentModel . DataAnnotations . ValidationAttribute > ( parameter , inherit : true ) ;
153+
154+ results . AddRange ( paramAttributes ) ;
155+
156+ break ;
157+ }
158+ }
159+
160+ return results . ToArray ( ) ;
161+ } ) ;
162+ }
163+ }
164+ }
0 commit comments