00001 using System.Collections.Generic; 00002 using System.Configuration; 00003 00004 namespace N2.Configuration 00005 { 00006 [ConfigurationCollection(typeof(FolderElement))] 00007 public class FileSystemFolderCollection : ConfigurationElementCollection 00008 { 00009 public FileSystemFolderCollection() 00010 { 00011 FolderElement folder = new FolderElement(); 00012 folder.Path = "~/upload/"; 00013 base.BaseAdd(folder); 00014 } 00015 00016 protected override ConfigurationElement CreateNewElement() 00017 { 00018 return new FolderElement(); 00019 } 00020 00021 protected override object GetElementKey(ConfigurationElement element) 00022 { 00023 return ((FolderElement)element).Path; 00024 } 00025 00026 public void Add(string folderPath) 00027 { 00028 BaseAdd(new FolderElement { Path = folderPath }); 00029 } 00030 00031 public FolderElement this[int index] 00032 { 00033 get { return (FolderElement)base.BaseGet(index); } 00034 } 00035 00036 public IEnumerable<string> Folders 00037 { 00038 get 00039 { 00040 foreach(FolderElement element in this) 00041 { 00042 if (element.Path.EndsWith("/")) 00043 yield return element.Path; 00044 else 00045 yield return element.Path + "/"; 00046 } 00047 } 00048 } 00049 } 00050 }