| File: System\ComponentModel\DataAnnotations\MetadataTypeAttribute.cs | Web Access |
| Project: src\runtime\src\libraries\System.ComponentModel.Annotations\src\System.ComponentModel.Annotations.csproj (System.ComponentModel.Annotations) |
// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using System; using System.Diagnostics.CodeAnalysis; namespace System.ComponentModel.DataAnnotations { /// <summary> /// Specifies the metadata class to associate with a data model class. /// </summary> [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] public sealed class MetadataTypeAttribute : Attribute { [DynamicallyAccessedMembers(AssociatedMetadataTypeTypeDescriptionProvider.AllMembersAndInterfaces)] private readonly Type _metadataClassType; /// <summary> /// Initializes a new instance of the System.ComponentModel.DataAnnotations.MetadataTypeAttribute /// class. /// </summary> /// <param name="metadataClassType">The metadata class to reference.</param> /// <exception cref="System.ArgumentNullException">metadataClassType is null.</exception> public MetadataTypeAttribute([DynamicallyAccessedMembers(AssociatedMetadataTypeTypeDescriptionProvider.AllMembersAndInterfaces)] Type metadataClassType) { _metadataClassType = metadataClassType; } /// <summary> /// Gets the metadata class that is associated with a data-model partial class. /// </summary> [DynamicallyAccessedMembers(AssociatedMetadataTypeTypeDescriptionProvider.AllMembersAndInterfaces)] public Type MetadataClassType { get { if (_metadataClassType == null) { throw new InvalidOperationException(SR.MetadataTypeAttribute_TypeCannotBeNull); } return _metadataClassType; } } } }