PageRenderTime 6ms CodeModel.GetById 1ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/tags/stable-1.2.0/Server/DefaultDocument/FilesCollection.cs

#
C# | 60 lines | 45 code | 7 blank | 8 comment | 4 complexity | 3cc1e7cb6f44bf3c81ec21a188aa0a5e MD5 | raw file
 1//-----------------------------------------------------------------------
 2// <copyright>
 3// Copyright (C) Ruslan Yakushev for the PHP Manager for IIS project.
 4//
 5// This file is subject to the terms and conditions of the Microsoft Public License (MS-PL).
 6// See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL for more details.
 7// </copyright>
 8//----------------------------------------------------------------------- 
 9
10using System;
11using Microsoft.Web.Administration;
12
13namespace Web.Management.PHP.DefaultDocument
14{
15
16    public sealed class FilesCollection : ConfigurationElementCollectionBase<FileElement>
17    {
18
19        public new FileElement this[string value]
20        {
21            get
22            {
23                for (int i = 0; (i < this.Count); i = (i + 1))
24                {
25                    FileElement element = base[i];
26                    if ((string.Equals(element.Value, value, StringComparison.OrdinalIgnoreCase) == true))
27                    {
28                        return element;
29                    }
30                }
31                return null;
32            }
33        }
34
35        public FileElement AddCopy(FileElement file)
36        {
37            FileElement element = CreateElement();
38            CopyAttributes(file, element);
39            return Add(element);
40        }
41
42        public FileElement AddCopyAt(int index, FileElement file)
43        {
44            FileElement element = CreateElement();
45            CopyAttributes(file, element);
46            return AddAt(index, element);
47        }
48
49        private static void CopyAttributes(ConfigurationElement source, ConfigurationElement destination)
50        {
51            foreach (ConfigurationAttribute attribute in source.Attributes)
52            {
53                if (!attribute.IsInheritedFromDefaultValue)
54                {
55                    destination[attribute.Name] = attribute.Value;
56                }
57            }
58        }
59    }
60}