Skip to content

Commit b92588d

Browse files
captainsafiasbomer
andauthored
Fix trim annotations on generated validation code (#61927)
* Fix trim annotations on generated validation code * Update snapshot outputs --------- Co-authored-by: Sven Boemer <[email protected]>
1 parent b47b064 commit b92588d

10 files changed

+30
-10
lines changed

src/Http/Http.Extensions/gen/Microsoft.AspNetCore.Http.ValidationsGenerator/Emitters/ValidationsGenerator.Emitter.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ public GeneratedValidatablePropertyInfo(
6767
Name = name;
6868
}
6969
70+
[global::System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(global::System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicProperties)]
7071
internal global::System.Type ContainingType { get; }
7172
internal string Name { get; }
7273
@@ -124,10 +125,11 @@ file static class GeneratedServiceCollectionExtensions
124125
{{GeneratedCodeAttribute}}
125126
file static class ValidationAttributeCache
126127
{
127-
private sealed record CacheKey(global::System.Type ContainingType, string PropertyName);
128+
private sealed record CacheKey([property: global::System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(global::System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicProperties)] global::System.Type ContainingType, string PropertyName);
128129
private static readonly global::System.Collections.Concurrent.ConcurrentDictionary<CacheKey, global::System.ComponentModel.DataAnnotations.ValidationAttribute[]> _cache = new();
129130
130131
public static global::System.ComponentModel.DataAnnotations.ValidationAttribute[] GetValidationAttributes(
132+
[global::System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(global::System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicProperties)]
131133
global::System.Type containingType,
132134
string propertyName)
133135
{

src/Http/Http.Extensions/test/ValidationsGenerator/snapshots/ValidationsGeneratorTests.CanValidateComplexTypes#ValidatableInfoResolver.g.verified.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public GeneratedValidatablePropertyInfo(
3939
Name = name;
4040
}
4141

42+
[global::System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(global::System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicProperties)]
4243
internal global::System.Type ContainingType { get; }
4344
internal string Name { get; }
4445

@@ -207,10 +208,11 @@ file static class GeneratedServiceCollectionExtensions
207208
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.ValidationsGenerator, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")]
208209
file static class ValidationAttributeCache
209210
{
210-
private sealed record CacheKey(global::System.Type ContainingType, string PropertyName);
211+
private sealed record CacheKey([property: global::System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(global::System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicProperties)] global::System.Type ContainingType, string PropertyName);
211212
private static readonly global::System.Collections.Concurrent.ConcurrentDictionary<CacheKey, global::System.ComponentModel.DataAnnotations.ValidationAttribute[]> _cache = new();
212213

213214
public static global::System.ComponentModel.DataAnnotations.ValidationAttribute[] GetValidationAttributes(
215+
[global::System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(global::System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicProperties)]
214216
global::System.Type containingType,
215217
string propertyName)
216218
{

src/Http/Http.Extensions/test/ValidationsGenerator/snapshots/ValidationsGeneratorTests.CanValidateIValidatableObject#ValidatableInfoResolver.g.verified.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public GeneratedValidatablePropertyInfo(
3939
Name = name;
4040
}
4141

42+
[global::System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(global::System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicProperties)]
4243
internal global::System.Type ContainingType { get; }
4344
internal string Name { get; }
4445

@@ -158,10 +159,11 @@ file static class GeneratedServiceCollectionExtensions
158159
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.ValidationsGenerator, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")]
159160
file static class ValidationAttributeCache
160161
{
161-
private sealed record CacheKey(global::System.Type ContainingType, string PropertyName);
162+
private sealed record CacheKey([property: global::System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(global::System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicProperties)] global::System.Type ContainingType, string PropertyName);
162163
private static readonly global::System.Collections.Concurrent.ConcurrentDictionary<CacheKey, global::System.ComponentModel.DataAnnotations.ValidationAttribute[]> _cache = new();
163164

164165
public static global::System.ComponentModel.DataAnnotations.ValidationAttribute[] GetValidationAttributes(
166+
[global::System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(global::System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicProperties)]
165167
global::System.Type containingType,
166168
string propertyName)
167169
{

src/Http/Http.Extensions/test/ValidationsGenerator/snapshots/ValidationsGeneratorTests.CanValidateParameters#ValidatableInfoResolver.g.verified.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public GeneratedValidatablePropertyInfo(
3939
Name = name;
4040
}
4141

42+
[global::System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(global::System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicProperties)]
4243
internal global::System.Type ContainingType { get; }
4344
internal string Name { get; }
4445

@@ -96,10 +97,11 @@ file static class GeneratedServiceCollectionExtensions
9697
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.ValidationsGenerator, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")]
9798
file static class ValidationAttributeCache
9899
{
99-
private sealed record CacheKey(global::System.Type ContainingType, string PropertyName);
100+
private sealed record CacheKey([property: global::System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(global::System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicProperties)] global::System.Type ContainingType, string PropertyName);
100101
private static readonly global::System.Collections.Concurrent.ConcurrentDictionary<CacheKey, global::System.ComponentModel.DataAnnotations.ValidationAttribute[]> _cache = new();
101102

102103
public static global::System.ComponentModel.DataAnnotations.ValidationAttribute[] GetValidationAttributes(
104+
[global::System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(global::System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicProperties)]
103105
global::System.Type containingType,
104106
string propertyName)
105107
{

src/Http/Http.Extensions/test/ValidationsGenerator/snapshots/ValidationsGeneratorTests.CanValidatePolymorphicTypes#ValidatableInfoResolver.g.verified.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public GeneratedValidatablePropertyInfo(
3939
Name = name;
4040
}
4141

42+
[global::System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(global::System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicProperties)]
4243
internal global::System.Type ContainingType { get; }
4344
internal string Name { get; }
4445

@@ -196,10 +197,11 @@ file static class GeneratedServiceCollectionExtensions
196197
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.ValidationsGenerator, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")]
197198
file static class ValidationAttributeCache
198199
{
199-
private sealed record CacheKey(global::System.Type ContainingType, string PropertyName);
200+
private sealed record CacheKey([property: global::System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(global::System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicProperties)] global::System.Type ContainingType, string PropertyName);
200201
private static readonly global::System.Collections.Concurrent.ConcurrentDictionary<CacheKey, global::System.ComponentModel.DataAnnotations.ValidationAttribute[]> _cache = new();
201202

202203
public static global::System.ComponentModel.DataAnnotations.ValidationAttribute[] GetValidationAttributes(
204+
[global::System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(global::System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicProperties)]
203205
global::System.Type containingType,
204206
string propertyName)
205207
{

src/Http/Http.Extensions/test/ValidationsGenerator/snapshots/ValidationsGeneratorTests.CanValidateRecordTypes#ValidatableInfoResolver.g.verified.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public GeneratedValidatablePropertyInfo(
3939
Name = name;
4040
}
4141

42+
[global::System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(global::System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicProperties)]
4243
internal global::System.Type ContainingType { get; }
4344
internal string Name { get; }
4445

@@ -238,10 +239,11 @@ file static class GeneratedServiceCollectionExtensions
238239
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.ValidationsGenerator, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")]
239240
file static class ValidationAttributeCache
240241
{
241-
private sealed record CacheKey(global::System.Type ContainingType, string PropertyName);
242+
private sealed record CacheKey([property: global::System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(global::System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicProperties)] global::System.Type ContainingType, string PropertyName);
242243
private static readonly global::System.Collections.Concurrent.ConcurrentDictionary<CacheKey, global::System.ComponentModel.DataAnnotations.ValidationAttribute[]> _cache = new();
243244

244245
public static global::System.ComponentModel.DataAnnotations.ValidationAttribute[] GetValidationAttributes(
246+
[global::System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(global::System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicProperties)]
245247
global::System.Type containingType,
246248
string propertyName)
247249
{

src/Http/Http.Extensions/test/ValidationsGenerator/snapshots/ValidationsGeneratorTests.CanValidateRecursiveTypes#ValidatableInfoResolver.g.verified.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public GeneratedValidatablePropertyInfo(
3939
Name = name;
4040
}
4141

42+
[global::System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(global::System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicProperties)]
4243
internal global::System.Type ContainingType { get; }
4344
internal string Name { get; }
4445

@@ -121,10 +122,11 @@ file static class GeneratedServiceCollectionExtensions
121122
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.ValidationsGenerator, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")]
122123
file static class ValidationAttributeCache
123124
{
124-
private sealed record CacheKey(global::System.Type ContainingType, string PropertyName);
125+
private sealed record CacheKey([property: global::System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(global::System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicProperties)] global::System.Type ContainingType, string PropertyName);
125126
private static readonly global::System.Collections.Concurrent.ConcurrentDictionary<CacheKey, global::System.ComponentModel.DataAnnotations.ValidationAttribute[]> _cache = new();
126127

127128
public static global::System.ComponentModel.DataAnnotations.ValidationAttribute[] GetValidationAttributes(
129+
[global::System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(global::System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicProperties)]
128130
global::System.Type containingType,
129131
string propertyName)
130132
{

src/Http/Http.Extensions/test/ValidationsGenerator/snapshots/ValidationsGeneratorTests.CanValidateTypeWithParsableProperties#ValidatableInfoResolver.g.verified.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public GeneratedValidatablePropertyInfo(
3939
Name = name;
4040
}
4141

42+
[global::System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(global::System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicProperties)]
4243
internal global::System.Type ContainingType { get; }
4344
internal string Name { get; }
4445

@@ -163,10 +164,11 @@ file static class GeneratedServiceCollectionExtensions
163164
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.ValidationsGenerator, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")]
164165
file static class ValidationAttributeCache
165166
{
166-
private sealed record CacheKey(global::System.Type ContainingType, string PropertyName);
167+
private sealed record CacheKey([property: global::System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(global::System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicProperties)] global::System.Type ContainingType, string PropertyName);
167168
private static readonly global::System.Collections.Concurrent.ConcurrentDictionary<CacheKey, global::System.ComponentModel.DataAnnotations.ValidationAttribute[]> _cache = new();
168169

169170
public static global::System.ComponentModel.DataAnnotations.ValidationAttribute[] GetValidationAttributes(
171+
[global::System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(global::System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicProperties)]
170172
global::System.Type containingType,
171173
string propertyName)
172174
{

src/Http/Http.Extensions/test/ValidationsGenerator/snapshots/ValidationsGeneratorTests.CanValidateTypesWithAttribute#ValidatableInfoResolver.g.verified.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public GeneratedValidatablePropertyInfo(
3939
Name = name;
4040
}
4141

42+
[global::System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(global::System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicProperties)]
4243
internal global::System.Type ContainingType { get; }
4344
internal string Name { get; }
4445

@@ -201,10 +202,11 @@ file static class GeneratedServiceCollectionExtensions
201202
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.ValidationsGenerator, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")]
202203
file static class ValidationAttributeCache
203204
{
204-
private sealed record CacheKey(global::System.Type ContainingType, string PropertyName);
205+
private sealed record CacheKey([property: global::System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(global::System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicProperties)] global::System.Type ContainingType, string PropertyName);
205206
private static readonly global::System.Collections.Concurrent.ConcurrentDictionary<CacheKey, global::System.ComponentModel.DataAnnotations.ValidationAttribute[]> _cache = new();
206207

207208
public static global::System.ComponentModel.DataAnnotations.ValidationAttribute[] GetValidationAttributes(
209+
[global::System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(global::System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicProperties)]
208210
global::System.Type containingType,
209211
string propertyName)
210212
{

src/Http/Http.Extensions/test/ValidationsGenerator/snapshots/ValidationsGeneratorTests.DoesNotEmitForExemptTypes#ValidatableInfoResolver.g.verified.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public GeneratedValidatablePropertyInfo(
3939
Name = name;
4040
}
4141

42+
[global::System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(global::System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicProperties)]
4243
internal global::System.Type ContainingType { get; }
4344
internal string Name { get; }
4445

@@ -115,10 +116,11 @@ file static class GeneratedServiceCollectionExtensions
115116
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.AspNetCore.Http.ValidationsGenerator, Version=42.42.42.42, Culture=neutral, PublicKeyToken=adb9793829ddae60", "42.42.42.42")]
116117
file static class ValidationAttributeCache
117118
{
118-
private sealed record CacheKey(global::System.Type ContainingType, string PropertyName);
119+
private sealed record CacheKey([property: global::System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(global::System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicProperties)] global::System.Type ContainingType, string PropertyName);
119120
private static readonly global::System.Collections.Concurrent.ConcurrentDictionary<CacheKey, global::System.ComponentModel.DataAnnotations.ValidationAttribute[]> _cache = new();
120121

121122
public static global::System.ComponentModel.DataAnnotations.ValidationAttribute[] GetValidationAttributes(
123+
[global::System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(global::System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicProperties)]
122124
global::System.Type containingType,
123125
string propertyName)
124126
{

0 commit comments

Comments
 (0)