Ejemplo n.º 1
0
        /// <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;
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public IDataWriter Find(string extension)
        {
            extension = DataWriterProvider.NormalizeExtension(extension);

            if (this.WritersByExt.ContainsKey(extension))
            {
                return(WritersByExt[extension]);
            }

            return(null);
        }