/// <summary> /// Creates new instance for type <paramref name="modelType"/>. /// </summary> /// <param name="modelType">Underlaying type for this model definition builder.</param> /// <param name="metadataReaderCollection">Collection attribute metadata readers.</param> public ReflectionModelDefinitionBuilder(Type modelType, AttributeMetadataReaderCollection metadataReaderCollection) { Ensure.NotNull(modelType, "modelType"); Ensure.NotNull(metadataReaderCollection, "metadataReaderCollection"); ModelType = modelType; MetadataReaderCollection = metadataReaderCollection; }
/// <summary> /// Creates new instance. /// </summary> /// <param name="metadataReaderCollection">Collection attribute metadata readers.</param> public ReflectionModelDefinitionFactory(AttributeMetadataReaderCollection metadataReaderCollection) { Ensure.NotNull(metadataReaderCollection, "metadataReaderCollection"); MetadataReaderCollection = metadataReaderCollection; }
/// <summary> /// Registers default search handler that for all types creates model definition by <see cref="ReflectionModelDefinitionBuilder"/>. /// </summary> /// <param name="collection">Model definition collection to register search handler to.</param> /// <param name="metadataReaders">Collection of metadata readers for <see cref="ReflectionModelDefinitionBuilder"/>.</param> /// <returns></returns> public static TypeModelDefinitionCollection AddReflectionSearchHandler(this TypeModelDefinitionCollection collection, AttributeMetadataReaderCollection metadataReaders) { Ensure.NotNull(collection, "collection"); Ensure.NotNull(metadataReaders, "metadataReaders"); collection.AddSearchHandler((Type type, out IModelDefinition model) => { model = new ReflectionModelDefinitionBuilder(type, metadataReaders).Create(); return(true); }); return(collection); }
/// <summary> /// Registers <typeparamref name="TAttribute"/> to be read by <paramref name="reader"/>. /// </summary> /// <typeparam name="TAttribute">Type of attribute.</typeparam> /// <param name="reader">Reader to process attributes of type <typeparamref name="TAttribute"/>.</param> /// <returns>Self (for fluency).</returns> public static AttributeMetadataReaderCollection Add <TAttribute>(this AttributeMetadataReaderCollection collection, AttributeMetadataReaderBase <TAttribute> reader) where TAttribute : Attribute { Ensure.NotNull(collection, "collection"); return(collection.Add(typeof(TAttribute), reader)); }