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 . GetPropertyValidationAttributes ( 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+ Type = type ;
59+ }
60+
61+ [ global ::System . Diagnostics . CodeAnalysis . DynamicallyAccessedMembers ( global ::System . Diagnostics . CodeAnalysis . DynamicallyAccessedMemberTypes . Interfaces ) ]
62+ internal global ::System . Type Type { get ; }
63+
64+ protected override global ::System . ComponentModel . DataAnnotations . ValidationAttribute [ ] GetValidationAttributes ( )
65+ => ValidationAttributeCache . GetTypeValidationAttributes ( Type ) ;
66+ }
67+
68+ [ global ::System . CodeDom . Compiler . GeneratedCodeAttribute ( "Microsoft.Extensions.Validation.ValidationsGenerator, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60" , "42.42.42.42" ) ]
69+ file class GeneratedValidatableInfoResolver : global ::Microsoft . Extensions . Validation . IValidatableInfoResolver
70+ {
71+ public bool TryGetValidatableTypeInfo ( global ::System . Type type , [ global ::System . Diagnostics . CodeAnalysis . NotNullWhen ( true ) ] out global ::Microsoft . Extensions . Validation . IValidatableInfo ? validatableInfo )
72+ {
73+ validatableInfo = null ;
74+ if ( type == typeof ( global ::BaseClass ) )
75+ {
76+ validatableInfo = new GeneratedValidatableTypeInfo (
77+ type : typeof ( global ::BaseClass ) ,
78+ members : [ ]
79+ ) ;
80+ return true ;
81+ }
82+ if ( type == typeof ( global ::DerivedClass ) )
83+ {
84+ validatableInfo = new GeneratedValidatableTypeInfo (
85+ type : typeof ( global ::DerivedClass ) ,
86+ members : [ ]
87+ ) ;
88+ return true ;
89+ }
90+
91+ return false ;
92+ }
93+
94+ // No-ops, rely on runtime code for ParameterInfo-based resolution
95+ public bool TryGetValidatableParameterInfo ( global ::System . Reflection . ParameterInfo parameterInfo , [ global ::System . Diagnostics . CodeAnalysis . NotNullWhen ( true ) ] out global ::Microsoft . Extensions . Validation . IValidatableInfo ? validatableInfo )
96+ {
97+ validatableInfo = null ;
98+ return false ;
99+ }
100+ }
101+
102+ [ global ::System . CodeDom . Compiler . GeneratedCodeAttribute ( "Microsoft.Extensions.Validation.ValidationsGenerator, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60" , "42.42.42.42" ) ]
103+ file static class GeneratedServiceCollectionExtensions
104+ {
105+ [ InterceptsLocation ]
106+ 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 )
107+ {
108+ // Use non-extension method to avoid infinite recursion.
109+ return global ::Microsoft . Extensions . DependencyInjection . ValidationServiceCollectionExtensions . AddValidation ( services , options =>
110+ {
111+ options . Resolvers . Insert ( 0 , new GeneratedValidatableInfoResolver ( ) ) ;
112+ if ( configureOptions is not null )
113+ {
114+ configureOptions ( options ) ;
115+ }
116+ } ) ;
117+ }
118+ }
119+
120+ [ global ::System . CodeDom . Compiler . GeneratedCodeAttribute ( "Microsoft.Extensions.Validation.ValidationsGenerator, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60" , "42.42.42.42" ) ]
121+ file static class ValidationAttributeCache
122+ {
123+ private sealed record CacheKey (
124+ [ param: global ::System . Diagnostics . CodeAnalysis . DynamicallyAccessedMembers ( global ::System . Diagnostics . CodeAnalysis . DynamicallyAccessedMemberTypes . PublicProperties | global ::System . Diagnostics . CodeAnalysis . DynamicallyAccessedMemberTypes . PublicConstructors ) ]
125+ [ property: global ::System . Diagnostics . CodeAnalysis . DynamicallyAccessedMembers ( global ::System . Diagnostics . CodeAnalysis . DynamicallyAccessedMemberTypes . PublicProperties | global ::System . Diagnostics . CodeAnalysis . DynamicallyAccessedMemberTypes . PublicConstructors ) ]
126+ global ::System . Type ContainingType ,
127+ string PropertyName ) ;
128+ private static readonly global ::System . Collections . Concurrent . ConcurrentDictionary < CacheKey , global ::System . ComponentModel . DataAnnotations . ValidationAttribute [ ] > _propertyCache = new ( ) ;
129+ private static readonly global ::System . Lazy < global ::System . Collections . Concurrent . ConcurrentDictionary < global ::System . Type , global ::System . ComponentModel . DataAnnotations . ValidationAttribute [ ] > > _lazyTypeCache = new ( ( ) => new ( ) ) ;
130+ private static global ::System . Collections . Concurrent . ConcurrentDictionary < global ::System . Type , global ::System . ComponentModel . DataAnnotations . ValidationAttribute [ ] > TypeCache => _lazyTypeCache . Value ;
131+
132+ public static global ::System . ComponentModel . DataAnnotations . ValidationAttribute [ ] GetPropertyValidationAttributes (
133+ [ global ::System . Diagnostics . CodeAnalysis . DynamicallyAccessedMembers ( global ::System . Diagnostics . CodeAnalysis . DynamicallyAccessedMemberTypes . PublicProperties | global ::System . Diagnostics . CodeAnalysis . DynamicallyAccessedMemberTypes . PublicConstructors ) ]
134+ global ::System . Type containingType ,
135+ string propertyName )
136+ {
137+ var key = new CacheKey ( containingType , propertyName ) ;
138+ return _propertyCache . GetOrAdd ( key , static k =>
139+ {
140+ var results = new global ::System . Collections . Generic . List < global ::System . ComponentModel . DataAnnotations . ValidationAttribute > ( ) ;
141+
142+ // Get attributes from the property
143+ var property = k . ContainingType . GetProperty ( k . PropertyName ) ;
144+ if ( property != null )
145+ {
146+ var propertyAttributes = global ::System . Reflection . CustomAttributeExtensions
147+ . GetCustomAttributes < global ::System . ComponentModel . DataAnnotations . ValidationAttribute > ( property , inherit : true ) ;
148+
149+ results . AddRange ( propertyAttributes ) ;
150+ }
151+
152+ // Check constructors for parameters that match the property name
153+ // to handle record scenarios
154+ foreach ( var constructor in k . ContainingType . GetConstructors ( ) )
155+ {
156+ // Look for parameter with matching name (case insensitive)
157+ var parameter = global ::System . Linq . Enumerable . FirstOrDefault (
158+ constructor . GetParameters ( ) ,
159+ p => string . Equals ( p . Name , k . PropertyName , global ::System . StringComparison . OrdinalIgnoreCase ) ) ;
160+
161+ if ( parameter != null )
162+ {
163+ var paramAttributes = global ::System . Reflection . CustomAttributeExtensions
164+ . GetCustomAttributes < global ::System . ComponentModel . DataAnnotations . ValidationAttribute > ( parameter , inherit : true ) ;
165+
166+ results . AddRange ( paramAttributes ) ;
167+
168+ break ;
169+ }
170+ }
171+
172+ return results . ToArray ( ) ;
173+ } ) ;
174+ }
175+
176+
177+ public static global ::System . ComponentModel . DataAnnotations . ValidationAttribute [ ] GetTypeValidationAttributes (
178+ [ global ::System . Diagnostics . CodeAnalysis . DynamicallyAccessedMembers ( global ::System . Diagnostics . CodeAnalysis . DynamicallyAccessedMemberTypes . Interfaces ) ]
179+ global ::System . Type type
180+ )
181+ {
182+ return TypeCache . GetOrAdd ( type , static t =>
183+ {
184+ var typeAttributes = global ::System . Reflection . CustomAttributeExtensions
185+ . GetCustomAttributes < global ::System . ComponentModel . DataAnnotations . ValidationAttribute > ( t , inherit : true ) ;
186+ return global ::System . Linq . Enumerable . ToArray ( typeAttributes ) ;
187+ } ) ;
188+ }
189+ }
190+ }
0 commit comments