/// <summary> /// Initializes a new instance of the <see cref="DefaultValueService" /> class. /// </summary> /// <param name="typeResolver">The type resolver.</param> /// <param name="typeRepository">The type repository.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="typeResolver" />, or <paramref name="typeRepository" /> are <c>null</c>.</exception> public DefaultValueService(ITypeResolver typeResolver, ITypeRepository typeRepository) { if (typeResolver == null) { throw new ArgumentNullException(nameof(typeResolver)); } if (typeRepository == null) { throw new ArgumentNullException(nameof(typeRepository)); } _typeResolver = typeResolver; _documentTypeModelFinder = new ContentTypeModelFinder <DocumentType, DocumentTypeAttribute, IContentType>(typeRepository); _mediaTypeModelFinder = new ContentTypeModelFinder <MediaType, MediaTypeAttribute, IMediaType>(typeRepository); _memberTypeModelFinder = new ContentTypeModelFinder <MemberType, MemberTypeAttribute, IMemberType>(typeRepository); }
/// <summary> /// Finds the models with a model type matching the specified model type, and then the content types matching any of those models. /// </summary> /// <param name="modelTypeNeedle">The model type to find the content types for.</param> /// <param name="modelsHaystack">The haystack of models.</param> /// <param name="contentTypesHaystack">The haystack of content types.</param> /// <returns>The content types found.</returns> /// <exception cref="ArgumentNullException">Thrown if <paramref name="modelTypeNeedle" />, <paramref name="modelsHaystack" />, or <paramref name="contentTypesHaystack" /> are <c>null</c>.</exception> public TContentType[] Find(Type modelTypeNeedle, TModel[] modelsHaystack, TContentType[] contentTypesHaystack) { if (modelTypeNeedle == null) { throw new ArgumentNullException(nameof(modelTypeNeedle)); } if (modelsHaystack == null) { throw new ArgumentNullException(nameof(modelsHaystack)); } if (contentTypesHaystack == null) { throw new ArgumentNullException(nameof(contentTypesHaystack)); } var modelNeedles = new ContentTypeModelFinder <TModel, TModelAttribute, TContentType>(_typeRepository).Find(modelTypeNeedle, modelsHaystack); return(Find(modelNeedles, contentTypesHaystack).Distinct(_comparer).ToArray()); }