コード例 #1
0
        /// <summary>
        /// Gets the metadata for a type.
        /// </summary>
        protected ModelMetadata GetModelMetadata(Type type)
        {
            var metadata = _metadataRepository.GetModelMetadata(type);

            if (metadata == null)
            {
                throw new ArgumentException("No metadata registered for " + type.FullName);
            }

            return(metadata);
        }
コード例 #2
0
        /// <summary>
        /// Gets the field metadata for a property of a model.
        /// </summary>
        /// <param name="modelType">The model type where the metadata is registered.</param>
        /// <param name="modelProperty">The property to get the metadata for.</param>
        /// <returns>Requested metadata, <c>null</c> if not found.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="modelType"/> or <paramref name="modelProperty"/> is null</exception>
        protected FieldMetadata GetFieldMetadata(Type modelType, ModelProperty modelProperty)
        {
            if (modelType == null)
            {
                throw new ArgumentNullException("modelType");
            }
            if (modelProperty == null)
            {
                throw new ArgumentNullException("modelProperty");
            }

            if (_metadataRepository == null)
            {
                _metadataRepository = ServiceRepository.Instance.FindService <IDataModelMetadataRepository>();
            }

            var metadata = _metadataRepository.GetModelMetadata(modelType);

            if (metadata != null)
            {
                return(metadata.GetFieldMetadata(modelProperty));
            }

            return(null);
        }