private string GetDefaultTemplateHint(ModelMetadataProvider provider, IEntityWithMetadata entityWithMetadata,
                                              Type containerType, Func <object> modelAccessor, Type modelType, string propertyName)
        {
            string result = null;

            if (modelType == typeof(List <Guid>))
            {
                result = "_ContentListPicker";
            }
            else if (modelType == typeof(Guid))
            {
                result = "_ContentPicker";
            }
            //else if (modelType == typeof(Content))
            //{
            //    result = propertyName == null ? "_Content" : "_ChildContentBuilder";
            //}
            //else if (modelType == typeof(List<Content>))
            //{
            //    result = "_ChildContentListBuilder";
            //}

            //switch (modelType --)
            //{
            //    case "System.Collections.Generic.List`1[[System.Guid, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]":
            //        return "_MultiSelectList";
            //}

            return(result);
        }
        private ContentModelMetadata GetContentModelMetadata(ModelMetadataProvider provider, IEntityWithMetadata entityWithMetadata, Type containerType, Func <object> modelAccessor, Type modelType, string propertyName)
        {
            var metadata = new ContentModelMetadata(provider, containerType, modelAccessor, modelType, propertyName);

            metadata.ShowForDisplay = entityWithMetadata.GetMetadataOrDefault <bool>("ShowForDisplay");

            string displayName;

            if (entityWithMetadata.TryGetMetadata("DisplayName", out displayName))
            {
                metadata.DisplayName = displayName;
            }

            string shortDisplayName;

            if (entityWithMetadata.TryGetMetadata("ShortDisplayName", out shortDisplayName))
            {
                metadata.ShortDisplayName = shortDisplayName;
            }

            string templateHint;

            if (entityWithMetadata.TryGetMetadata("TemplateHint", out templateHint))
            {
                metadata.TemplateHint = templateHint;
            }
            else
            {
                metadata.TemplateHint = GetDefaultTemplateHint(provider, entityWithMetadata, containerType, modelAccessor, modelType, propertyName);
            }

            string description;

            if (entityWithMetadata.TryGetMetadata("Description", out description))
            {
                metadata.Description = description;
            }

            string nullDisplayText;

            if (entityWithMetadata.TryGetMetadata("NullDisplayText", out nullDisplayText))
            {
                metadata.NullDisplayText = nullDisplayText;
            }

            string watermark;

            if (entityWithMetadata.TryGetMetadata("Watermark", out watermark))
            {
                metadata.Watermark = watermark;
            }

            bool hideSurroundingHtml;

            if (entityWithMetadata.TryGetMetadata("HideSurroundingHtml", out hideSurroundingHtml))
            {
                metadata.HideSurroundingHtml = hideSurroundingHtml;
            }

            bool requestValidationEnabled;

            if (entityWithMetadata.TryGetMetadata("RequestValidationEnabled", out requestValidationEnabled))
            {
                metadata.RequestValidationEnabled = requestValidationEnabled;
            }

            bool isReadOnly;

            if (entityWithMetadata.TryGetMetadata("IsReadOnly", out isReadOnly))
            {
                metadata.IsReadOnly = isReadOnly;
            }

            bool isRequired;

            if (entityWithMetadata.TryGetMetadata("IsRequired", out isRequired))
            {
                metadata.IsRequired = isRequired;
            }

            bool showForEdit;

            if (entityWithMetadata.TryGetMetadata("ShowForEdit", out showForEdit))
            {
                metadata.ShowForEdit = showForEdit;
            }
            else
            {
                metadata.ShowForEdit = !metadata.IsReadOnly;
            }

            int order;

            if (entityWithMetadata.TryGetMetadata("Order", out order))
            {
                metadata.Order = order;
            }

            string displayFormatString;

            if (entityWithMetadata.TryGetMetadata("DisplayFormatString", out displayFormatString))
            {
                metadata.DisplayFormatString = displayFormatString;
            }


            string editFormatString;

            if (entityWithMetadata.GetMetadataOrDefault <bool>("ApplyFormatInEditMode") && metadata.ShowForEdit && entityWithMetadata.TryGetMetadata("EditFormatString", out editFormatString))
            {
                metadata.EditFormatString = editFormatString;
            }

            bool convertEmptyStringToNull;

            if (entityWithMetadata.TryGetMetadata("ConvertEmptyStringToNull", out convertEmptyStringToNull))
            {
                metadata.ConvertEmptyStringToNull = convertEmptyStringToNull;
            }

            return(metadata);
        }