Exemplo n.º 1
0
 public void RegisterModelMetadataWrapper(ModelMetadataWrapper modelMetadataWrapper)
 {
     if (!_modelMetadataWrapperCache.ContainsKey(modelMetadataWrapper.ModelTypeId))
     {
         _modelMetadataWrapperCache[modelMetadataWrapper.ModelTypeId] = modelMetadataWrapper;
     }
 }
Exemplo n.º 2
0
 /// <inheritdoc />
 public bool TryGet(string modelTypeId, out ModelMetadataWrapper modelMetadataWrapper)
 {
     if (_modelTypeCache.ContainsKey(modelTypeId))
     {
         Type modelType = _modelTypeCache[modelTypeId];
         modelMetadataWrapper = GetOrCreate(modelType);
         return(true);
     }
     modelMetadataWrapper = null;
     return(false);
 }
Exemplo n.º 3
0
        public ModelMetadataWrapper GetOrCreate(Type modelType)
        {
            ModelMetadataWrapper modelMetadataWrapper;
            var modelTypeId = modelType.GetTypeId();

            if (_modelMetadataWrapperCache.ContainsKey(modelTypeId))
            {
                modelMetadataWrapper = _modelMetadataWrapperCache[modelTypeId];
            }
            else
            {
                ModelMetadata modelMetadata = _modelMetadataProvider.GetMetadataForType(modelType);

                modelMetadataWrapper = new ModelMetadataWrapper(modelMetadata, this)
                {
                    Description = _documentationProvider.GetDocumentation(modelType.GetTypeInfo())
                };

                var modelTypeInfo = modelType.GetTypeInfo();
                foreach (var property in modelMetadata.Properties)
                {
                    var propertyInfo    = modelTypeInfo.GetProperty(property.PropertyName);
                    var propertyWrapper = new ModelMetadataPropertyWrapper(property, this)
                    {
                        Description = _documentationProvider.GetDocumentation(propertyInfo)
                    };
                    modelMetadataWrapper.Properties.Add(propertyWrapper);
                }
                if (modelMetadata.IsEnum)
                {
                    foreach (var enumNameAndValue in modelMetadata.EnumNamesAndValues)
                    {
                        var enumFieldDescription = new EnumFieldDescription
                        {
                            Name        = enumNameAndValue.Key,
                            Value       = enumNameAndValue.Value,
                            Description = _documentationProvider.GetDocumentation(modelTypeInfo.GetField(enumNameAndValue.Key))
                        };
                        modelMetadataWrapper.EnumFieldDescrptions.Add(enumFieldDescription);
                    }
                }
            }
            return(modelMetadataWrapper);
        }