// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using Microsoft.AspNetCore.Mvc.ModelBinding; namespace Microsoft.AspNetCore.Mvc.ApplicationModels { /// /// A type which is used to represent a property in a . /// [DebuggerDisplay("PropertyModel: Name={PropertyName}")] public class PropertyModel : ICommonModel, IBindingModel { /// /// Creates a new instance of . /// /// The for the underlying property. /// Any attributes which are annotated on the property. public PropertyModel( PropertyInfo propertyInfo, IReadOnlyList attributes) { if (propertyInfo == null) { throw new ArgumentNullException(nameof(propertyInfo)); } if (attributes == null) { throw new ArgumentNullException(nameof(attributes)); } PropertyInfo = propertyInfo; Properties = new Dictionary(); Attributes = new List(attributes); } /// /// Creats a new instance of from a given . /// /// The which needs to be copied. public PropertyModel(PropertyModel other) { if (other == null) { throw new ArgumentNullException(nameof(other)); } Controller = other.Controller; Attributes = new List(other.Attributes); BindingInfo = BindingInfo == null ? null : new BindingInfo(other.BindingInfo); PropertyInfo = other.PropertyInfo; PropertyName = other.PropertyName; Properties = new Dictionary(other.Properties); } /// /// Gets or sets the this is associated with. /// public ControllerModel Controller { get; set; } /// /// Gets any attributes which are annotated on the property. /// public IReadOnlyList Attributes { get; } public IDictionary Properties { get; } MemberInfo ICommonModel.MemberInfo => PropertyInfo; string ICommonModel.Name => PropertyName; /// /// Gets or sets the associated with this model. /// public BindingInfo BindingInfo { get; set; } /// /// Gets the underlying . /// public PropertyInfo PropertyInfo { get; } /// /// Gets or sets the name of the property represented by this model. /// public string PropertyName { get; set; } } }