namespace System.ComponentModel.DataAnnotations
{
- // TODO-NULLABLE: Enable after System.ComponentModel.TypeDescriptionProvider is annotated
-#nullable disable
public partial class AssociatedMetadataTypeTypeDescriptionProvider : System.ComponentModel.TypeDescriptionProvider
{
public AssociatedMetadataTypeTypeDescriptionProvider(System.Type type) { }
public AssociatedMetadataTypeTypeDescriptionProvider(System.Type type, [System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All)] System.Type associatedMetadataType) { }
- public override System.ComponentModel.ICustomTypeDescriptor GetTypeDescriptor([System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All)] System.Type objectType, object instance) { throw null; }
+ public override System.ComponentModel.ICustomTypeDescriptor GetTypeDescriptor([System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All)] System.Type objectType, object? instance) { throw null; }
}
-#nullable enable
[System.AttributeUsageAttribute(System.AttributeTargets.Field | System.AttributeTargets.Property, AllowMultiple=false, Inherited=true)]
[System.ObsoleteAttribute("AssociationAttribute has been deprecated and is not supported.")]
public sealed partial class AssociationAttribute : System.Attribute
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// TODO-NULLABLE: Enable after System.ComponentModel.TypeDescriptionProvider is annotated
-#nullable disable
-
using System.Diagnostics.CodeAnalysis;
namespace System.ComponentModel.DataAnnotations
public class AssociatedMetadataTypeTypeDescriptionProvider : TypeDescriptionProvider
{
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]
- private readonly Type _associatedMetadataType;
+ private readonly Type? _associatedMetadataType;
/// <summary>
/// Initializes a new instance of the System.ComponentModel.DataAnnotations.AssociatedMetadataTypeTypeDescriptionProvider
/// <param name="objectType">The type of object to retrieve the type descriptor for.</param>
/// <param name="instance">An instance of the type.</param>
/// <returns>The descriptor that provides metadata for the type.</returns>
- public override ICustomTypeDescriptor GetTypeDescriptor([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type objectType, object instance)
+ public override ICustomTypeDescriptor GetTypeDescriptor([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type objectType, object? instance)
{
- ICustomTypeDescriptor baseDescriptor = base.GetTypeDescriptor(objectType, instance);
+ ICustomTypeDescriptor? baseDescriptor = base.GetTypeDescriptor(objectType, instance);
return new AssociatedMetadataTypeTypeDescriptor(baseDescriptor, objectType, _associatedMetadataType);
}
}
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// TODO-NULLABLE: Enable after System.ComponentModel.TypeDescriptionProvider is annotated
-#nullable disable
-
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
internal sealed class AssociatedMetadataTypeTypeDescriptor : CustomTypeDescriptor
{
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]
- private Type AssociatedMetadataType { get; set; }
+ private Type? AssociatedMetadataType { get; set; }
private bool IsSelfAssociated { get; set; }
public AssociatedMetadataTypeTypeDescriptor(
- ICustomTypeDescriptor parent,
+ ICustomTypeDescriptor? parent,
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] Type type,
- [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type associatedMetadataType)
+ [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type? associatedMetadataType)
: base(parent)
{
AssociatedMetadataType = associatedMetadataType ?? TypeDescriptorCache.GetAssociatedMetadataType(type);
}
[RequiresUnreferencedCode("PropertyDescriptor's PropertyType cannot be statically discovered. The public parameterless constructor or the 'Default' static field may be trimmed from the Attribute's Type.")]
- public override PropertyDescriptorCollection GetProperties(Attribute[] attributes)
+ public override PropertyDescriptorCollection GetProperties(Attribute[]? attributes)
{
return GetPropertiesWithMetadata(base.GetProperties(attributes));
}
private static class TypeDescriptorCache
{
// Stores the associated metadata type for a type
- private static readonly ConcurrentDictionary<Type, Type> s_metadataTypeCache = new ConcurrentDictionary<Type, Type>();
+ private static readonly ConcurrentDictionary<Type, Type?> s_metadataTypeCache = new ConcurrentDictionary<Type, Type?>();
// Stores the attributes for a member info
private static readonly ConcurrentDictionary<(Type, string), Attribute[]> s_typeMemberCache = new ConcurrentDictionary<(Type, string), Attribute[]>();
}
[return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]
- public static Type GetAssociatedMetadataType(Type type)
+ public static Type? GetAssociatedMetadataType(Type type)
{
- Type associatedMetadataType = null;
+ Type? associatedMetadataType;
if (s_metadataTypeCache.TryGetValue(type, out associatedMetadataType))
{
return associatedMetadataType;
}
// Try association attribute
- MetadataTypeAttribute attribute = (MetadataTypeAttribute)Attribute.GetCustomAttribute(type, typeof(MetadataTypeAttribute));
+ MetadataTypeAttribute? attribute = (MetadataTypeAttribute?)Attribute.GetCustomAttribute(type, typeof(MetadataTypeAttribute));
if (attribute != null)
{
associatedMetadataType = attribute.MetadataClassType;
string memberName)
{
(Type, string) memberTuple = (type, memberName);
- Attribute[] attributes;
+ Attribute[]? attributes;
if (s_typeMemberCache.TryGetValue(memberTuple, out attributes))
{
return attributes;
// Only public static/instance members
BindingFlags searchFlags = BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static;
// Try to find a matching member on type
- MemberInfo matchingMember = type.GetMember(memberName, allowedMemberTypes, searchFlags).FirstOrDefault();
+ MemberInfo? matchingMember = type.GetMember(memberName, allowedMemberTypes, searchFlags).FirstOrDefault();
if (matchingMember != null)
{
attributes = Attribute.GetCustomAttributes(matchingMember, true /* inherit */);