Skip to content

Commit

Permalink
Use better trimming message in ValidationContext (#84326)
Browse files Browse the repository at this point in the history
* Use better trimming message in ValidationContext

Add more details about why ValidationContext requires unreferenced code.

Fix #84324

* Exclude RequiresUnreferencedCodeAttribute from baseline API compat
  • Loading branch information
eerhardt authored Apr 6, 2023
1 parent 71deac7 commit c93a93b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

namespace System.ComponentModel.DataAnnotations
{
[System.AttributeUsageAttribute(System.AttributeTargets.Field | System.AttributeTargets.Parameter | System.AttributeTargets.Property, AllowMultiple = false)]
[System.CLSCompliant(false)]
[System.AttributeUsageAttribute(System.AttributeTargets.Field | System.AttributeTargets.Parameter | System.AttributeTargets.Property, AllowMultiple=false)]
[System.CLSCompliantAttribute(false)]
public partial class AllowedValuesAttribute : System.ComponentModel.DataAnnotations.ValidationAttribute
{
public AllowedValuesAttribute(params object?[] values) { }
Expand All @@ -32,8 +32,8 @@ public AssociationAttribute(string name, string thisKey, string otherKey) { }
public string ThisKey { get { throw null; } }
public System.Collections.Generic.IEnumerable<string> ThisKeyMembers { get { throw null; } }
}
[System.AttributeUsageAttribute(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false)]
public class Base64StringAttribute : ValidationAttribute
[System.AttributeUsageAttribute(System.AttributeTargets.Field | System.AttributeTargets.Parameter | System.AttributeTargets.Property, AllowMultiple=false)]
public partial class Base64StringAttribute : System.ComponentModel.DataAnnotations.ValidationAttribute
{
public Base64StringAttribute() { }
public override bool IsValid(object? value) { throw null; }
Expand Down Expand Up @@ -101,8 +101,8 @@ public DataTypeAttribute(string customDataType) { }
public virtual string GetDataTypeName() { throw null; }
public override bool IsValid(object? value) { throw null; }
}
[System.AttributeUsageAttribute(System.AttributeTargets.Field | System.AttributeTargets.Parameter | System.AttributeTargets.Property, AllowMultiple = false)]
[System.CLSCompliant(false)]
[System.AttributeUsageAttribute(System.AttributeTargets.Field | System.AttributeTargets.Parameter | System.AttributeTargets.Property, AllowMultiple=false)]
[System.CLSCompliantAttribute(false)]
public partial class DeniedValuesAttribute : System.ComponentModel.DataAnnotations.ValidationAttribute
{
public DeniedValuesAttribute(params object?[] values) { }
Expand Down Expand Up @@ -205,13 +205,13 @@ public sealed partial class KeyAttribute : System.Attribute
{
public KeyAttribute() { }
}
[System.AttributeUsageAttribute(System.AttributeTargets.Field | System.AttributeTargets.Parameter | System.AttributeTargets.Property, AllowMultiple = false)]
[System.AttributeUsageAttribute(System.AttributeTargets.Field | System.AttributeTargets.Parameter | System.AttributeTargets.Property, AllowMultiple=false)]
public partial class LengthAttribute : System.ComponentModel.DataAnnotations.ValidationAttribute
{
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Uses reflection to get the 'Count' property on types that don't implement ICollection. This 'Count' property may be trimmed. Ensure it is preserved.")]
public LengthAttribute(int minimumLength, int maximumLength) { }
public int MinimumLength { get { throw null; } }
public int MaximumLength { get { throw null; } }
public int MinimumLength { get { throw null; } }
public override string FormatErrorMessage(string name) { throw null; }
public override bool IsValid(object? value) { throw null; }
}
Expand Down Expand Up @@ -270,8 +270,8 @@ public RangeAttribute([System.Diagnostics.CodeAnalysis.DynamicallyAccessedMember
public partial class RegularExpressionAttribute : System.ComponentModel.DataAnnotations.ValidationAttribute
{
public RegularExpressionAttribute([System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("Regex")] string pattern) { }
public int MatchTimeoutInMilliseconds { get { throw null; } set { } }
public System.TimeSpan MatchTimeout { get { throw null; } }
public int MatchTimeoutInMilliseconds { get { throw null; } set { } }
public string Pattern { get { throw null; } }
public override string FormatErrorMessage(string name) { throw null; }
public override bool IsValid(object? value) { throw null; }
Expand Down Expand Up @@ -342,11 +342,11 @@ public void Validate(object? value, string name) { }
}
public sealed partial class ValidationContext : System.IServiceProvider
{
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("The Type of instance cannot be statically discovered.")]
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("The Type of instance cannot be statically discovered and the Type's properties can be trimmed.")]
public ValidationContext(object instance) { }
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("The Type of instance cannot be statically discovered.")]
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("The Type of instance cannot be statically discovered and the Type's properties can be trimmed.")]
public ValidationContext(object instance, System.Collections.Generic.IDictionary<object, object?>? items) { }
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("The Type of instance cannot be statically discovered.")]
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("The Type of instance cannot be statically discovered and the Type's properties can be trimmed.")]
public ValidationContext(object instance, System.IServiceProvider? serviceProvider, System.Collections.Generic.IDictionary<object, object?>? items) { }
public string DisplayName { get { throw null; } set { } }
public System.Collections.Generic.IDictionary<object, object?> Items { get { throw null; } }
Expand Down Expand Up @@ -380,16 +380,16 @@ public ValidationResult(string? errorMessage, System.Collections.Generic.IEnumer
}
public static partial class Validator
{
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("The Type of instance cannot be statically discovered.")]
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("The Type of instance cannot be statically discovered and the Type's properties can be trimmed.")]
public static bool TryValidateObject(object instance, System.ComponentModel.DataAnnotations.ValidationContext validationContext, System.Collections.Generic.ICollection<System.ComponentModel.DataAnnotations.ValidationResult>? validationResults) { throw null; }
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("The Type of instance cannot be statically discovered.")]
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("The Type of instance cannot be statically discovered and the Type's properties can be trimmed.")]
public static bool TryValidateObject(object instance, System.ComponentModel.DataAnnotations.ValidationContext validationContext, System.Collections.Generic.ICollection<System.ComponentModel.DataAnnotations.ValidationResult>? validationResults, bool validateAllProperties) { throw null; }
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("The Type of validationContext.ObjectType cannot be statically discovered.")]
public static bool TryValidateProperty(object? value, System.ComponentModel.DataAnnotations.ValidationContext validationContext, System.Collections.Generic.ICollection<System.ComponentModel.DataAnnotations.ValidationResult>? validationResults) { throw null; }
public static bool TryValidateValue(object value, System.ComponentModel.DataAnnotations.ValidationContext validationContext, System.Collections.Generic.ICollection<System.ComponentModel.DataAnnotations.ValidationResult>? validationResults, System.Collections.Generic.IEnumerable<System.ComponentModel.DataAnnotations.ValidationAttribute> validationAttributes) { throw null; }
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("The Type of instance cannot be statically discovered.")]
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("The Type of instance cannot be statically discovered and the Type's properties can be trimmed.")]
public static void ValidateObject(object instance, System.ComponentModel.DataAnnotations.ValidationContext validationContext) { }
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("The Type of instance cannot be statically discovered.")]
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("The Type of instance cannot be statically discovered and the Type's properties can be trimmed.")]
public static void ValidateObject(object instance, System.ComponentModel.DataAnnotations.ValidationContext validationContext, bool validateAllProperties) { }
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("The Type of validationContext.ObjectType cannot be statically discovered.")]
public static void ValidateProperty(object? value, System.ComponentModel.DataAnnotations.ValidationContext validationContext) { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public sealed class ValidationContext
// Also we use this ability in Validator.CreateValidationContext()??
: IServiceProvider
{
internal const string InstanceTypeNotStaticallyDiscovered = "The Type of instance cannot be statically discovered.";
internal const string InstanceTypeNotStaticallyDiscovered = "The Type of instance cannot be statically discovered and the Type's properties can be trimmed.";

#region Member Fields

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// These attributes shouldn't be checked against baseline reference assemblies

T:System.CLSCompliantAttribute
T:System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute
T:System.ComponentModel.EditorBrowsableAttribute
T:System.ObsoleteAttribute

0 comments on commit c93a93b

Please sign in to comment.