public void CreateBindingMetadata(BindingMetadataProviderContext context)
        {
            if (context.Key.ContainerType == null || context.Key.MetadataKind != ModelMetadataKind.Property)
            {
                return;
            }

            var m = registry.GetModelPropertyMetadata(context.Key.ContainerType, context.Key.Name);

            if (m?.IsReadOnly != null)
            {
                context.BindingMetadata.IsReadOnly = m.IsReadOnly;
            }
        }
        /// <summary>
        /// Gets metadata for the specified property.
        /// </summary>
        /// <param name="modelAccessor">The model accessor.</param>
        /// <param name="containerType">The type of the container.</param>
        /// <param name="propertyName">The property to get the metadata model for.</param>
        /// <returns>
        /// The metadata model for the specified property.
        /// </returns>
        public override ModelMetadata GetMetadataForProperty(Func <object> modelAccessor, [NotNull] Type containerType, [NotNull] string propertyName)
        {
            Invariant.IsNotNull(containerType, "containerType");
            Invariant.IsNotNull(propertyName, "propertyName");

            var metadataItem = registry.GetModelPropertyMetadata(containerType, propertyName);

            if (metadataItem == null)
            {
                return(base.GetMetadataForProperty(modelAccessor, containerType, propertyName));
            }

            var propertyDescriptor = TypeDescriptor.GetProperties(containerType)
                                     .Cast <PropertyDescriptor>()
                                     .FirstOrDefault(property => property.Name.Equals(propertyName, StringComparison.OrdinalIgnoreCase));

            if (propertyDescriptor == null)
            {
                throw new ArgumentException(
                          string.Format(
                              CultureInfo.CurrentUICulture,
                              ExceptionMessages.ThePropertyNameOfTypeCouldNotBeFound,
                              containerType.FullName,
                              propertyName));
            }

            return(CreatePropertyMetadata(containerType, propertyName, propertyDescriptor.PropertyType, metadataItem, modelAccessor));
        }