/// <summary> /// Ctor /// </summary> /// <param name="writers">inject with all possible writers</param> public DataWriterProvider(IEnumerable <IDataWriter> writers) { if (writers != null) { foreach (IDataWriter writer in writers) { if (this.DefaultWriter == null) { // TODO: decide less arbitrary way to choose default // without hardcoding value into IDataWriter this.DefaultWriter = writer; } if (!String.IsNullOrEmpty(writer.ContentType)) { this.WritersByMime[writer.ContentType] = writer; } if (!String.IsNullOrEmpty(writer.ContentType)) { string ext = DataWriterProvider.NormalizeExtension(writer.FileExtension); this.WritersByExt[ext] = writer; } } } }
public IDataWriter Find(string extension) { extension = DataWriterProvider.NormalizeExtension(extension); if (this.WritersByExt.ContainsKey(extension)) { return(WritersByExt[extension]); } return(null); }