Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
PropertyItemCollection.cs
Go to the documentation of this file.
1 #region License
2 
3 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
4 // This file is distributed under MIT License. See LICENSE.md for details.
5 //
6 // SLNTools
7 // Copyright (c) 2009
8 // by Christian Warren
9 //
10 // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
11 // documentation files (the "Software"), to deal in the Software without restriction, including without limitation
12 // the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
13 // to permit persons to whom the Software is furnished to do so, subject to the following conditions:
14 //
15 // The above copyright notice and this permission notice shall be included in all copies or substantial portions
16 // of the Software.
17 //
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
19 // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
21 // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 // DEALINGS IN THE SOFTWARE.
23 
24 #endregion
25 
26 using System;
27 using System.Collections.Generic;
28 using System.Collections.ObjectModel;
29 using System.Diagnostics;
30 
31 namespace SiliconStudio.Core.VisualStudio
32 {
33  /// <summary>
34  /// A collection of <see cref="PropertyItem"/>
35  /// </summary>
36  [DebuggerDisplay("Count = {Count}")]
37  public sealed class PropertyItemCollection
38  : KeyedCollection<string, PropertyItem>
39  {
40  /// <summary>
41  /// Initializes a new instance of the <see cref="PropertyItemCollection"/> class.
42  /// </summary>
44  : base(StringComparer.InvariantCultureIgnoreCase)
45  {
46  }
47 
48  /// <summary>
49  /// Initializes a new instance of the <see cref="PropertyItemCollection"/> class.
50  /// </summary>
51  /// <param name="items">The items to copy from.</param>
53  : this()
54  {
55  this.AddRange(items);
56  }
57 
58  protected override string GetKeyForItem(PropertyItem item)
59  {
60  return item.Name;
61  }
62 
63  protected override void InsertItem(int index, PropertyItem item)
64  {
65  PropertyItem existingItem = (Contains(GetKeyForItem(item))) ? this[GetKeyForItem(item)] : null;
66 
67  if (existingItem == null)
68  {
69  // Add a clone of the item instead of the item itself
70  base.InsertItem(index, item.Clone());
71  }
72  else if (item.Value != existingItem.Value)
73  {
74  existingItem.Value = item.Value;
75  }
76  }
77 
78  protected override void SetItem(int index, PropertyItem item)
79  {
80  // Add a clone of the item instead of the item itself
81  base.SetItem(index, item.Clone());
82  }
83  }
84 }
string Value
Gets or sets the value.
Definition: PropertyItem.cs:70
override void InsertItem(int index, PropertyItem item)
A key/value pair used by PropertyItemCollection
Definition: PropertyItem.cs:33
PropertyItemCollection(IEnumerable< PropertyItem > items)
Initializes a new instance of the PropertyItemCollection class.
override void SetItem(int index, PropertyItem item)
PropertyItemCollection()
Initializes a new instance of the PropertyItemCollection class.