Changeset 2830 for trunk/sources/HeuristicLab.Core/3.3
- Timestamp:
- 02/19/10 02:15:10 (14 years ago)
- Location:
- trunk/sources/HeuristicLab.Core/3.3
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Core/3.3/DeepCloneable.cs
r2790 r2830 21 21 22 22 using System; 23 using System.Collections.Generic;24 using System.Text;25 using System.Xml;26 23 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 27 24 -
trunk/sources/HeuristicLab.Core/3.3/Item.cs
r2790 r2830 20 20 #endregion 21 21 22 using System;23 using System.Collections.Generic;24 using System.ComponentModel;25 using System.Text;26 using System.Xml;27 22 using System.Drawing; 28 using System.Resources;23 using HeuristicLab.Common.Resources; 29 24 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 30 using HeuristicLab.Common.Resources;31 25 32 26 namespace HeuristicLab.Core { … … 61 55 protected virtual void OnChanged(ChangedEventArgs e) { 62 56 if ((e.RegisterChangedObject(this)) && (Changed != null)) 63 57 Changed(this, e); 64 58 } 65 59 } -
trunk/sources/HeuristicLab.Core/3.3/ItemArray.cs
r2790 r2830 21 21 22 22 using System; 23 using System.Linq; 23 24 using System.Collections; 24 25 using System.Collections.Generic; … … 55 56 public ItemArray() : base() { } 56 57 public ItemArray(int length) : base(length) { } 57 public ItemArray(T[] array) : base(array) { } 58 public ItemArray(IEnumerable<T> collection) : base(collection) { } 58 public ItemArray(T[] array) : base(array) { 59 foreach (T item in this) 60 item.Changed += new ChangedEventHandler(Item_Changed); 61 } 62 public ItemArray(IEnumerable<T> collection) : base(collection) { 63 foreach (T item in this) 64 item.Changed += new ChangedEventHandler(Item_Changed); 65 } 59 66 60 67 public object Clone() { … … 62 69 } 63 70 64 public IDeepCloneable Clone(Cloner cloner) { 65 T[] items = new T[Length]; 66 for (int i = 0; i < items.Length; i++) 67 items[i] = (T)cloner.Clone(this[i]); 68 ItemArray<T> clone = (ItemArray<T>)Activator.CreateInstance(this.GetType(), new object[] { items }); 71 public virtual IDeepCloneable Clone(Cloner cloner) { 72 ItemArray<T> clone = (ItemArray<T>)Activator.CreateInstance(this.GetType(), this.Select(x => (T)cloner.Clone(x))); 69 73 cloner.RegisterClonedObject(this, clone); 70 74 return clone; -
trunk/sources/HeuristicLab.Core/3.3/ItemCollection.cs
r2790 r2830 21 21 22 22 using System; 23 using System.Linq; 23 24 using System.Collections; 24 25 using System.Collections.Generic; … … 56 57 public ItemCollection() : base() { } 57 58 public ItemCollection(int capacity) : base(capacity) { } 58 public ItemCollection(IEnumerable<T> collection) : base(collection) { } 59 public ItemCollection(IEnumerable<T> collection) : base(collection) { 60 foreach (T item in this) 61 item.Changed += new ChangedEventHandler(Item_Changed); 62 } 59 63 60 64 public object Clone() { … … 62 66 } 63 67 64 public IDeepCloneable Clone(Cloner cloner) { 65 List<T> items = new List<T>(); 66 foreach (T item in this) 67 items.Add((T)cloner.Clone(item)); 68 ItemCollection<T> clone = (ItemCollection<T>)Activator.CreateInstance(this.GetType(), items); 68 public virtual IDeepCloneable Clone(Cloner cloner) { 69 ItemCollection<T> clone = (ItemCollection<T>)Activator.CreateInstance(this.GetType(), this.Select(x => (T)cloner.Clone(x))); 69 70 cloner.RegisterClonedObject(this, clone); 70 71 return clone; -
trunk/sources/HeuristicLab.Core/3.3/ItemList.cs
r2790 r2830 21 21 22 22 using System; 23 using System.Linq; 23 24 using System.Collections; 24 25 using System.Collections.Generic; … … 56 57 public ItemList() : base() { } 57 58 public ItemList(int capacity) : base(capacity) { } 58 public ItemList(IEnumerable<T> collection) : base(collection) { } 59 public ItemList(IEnumerable<T> collection) : base(collection) { 60 foreach (T item in this) 61 item.Changed += new ChangedEventHandler(Item_Changed); 62 } 59 63 60 64 public object Clone() { … … 62 66 } 63 67 64 public IDeepCloneable Clone(Cloner cloner) { 65 List<T> items = new List<T>(); 66 foreach (T item in this) 67 items.Add((T)cloner.Clone(item)); 68 ItemList<T> clone = (ItemList<T>)Activator.CreateInstance(this.GetType(), items); 68 public virtual IDeepCloneable Clone(Cloner cloner) { 69 ItemList<T> clone = (ItemList<T>)Activator.CreateInstance(this.GetType(), this.Select(x => (T)cloner.Clone(x))); 69 70 cloner.RegisterClonedObject(this, clone); 70 71 return clone; -
trunk/sources/HeuristicLab.Core/3.3/ItemSet.cs
r2790 r2830 21 21 22 22 using System; 23 using System.Linq; 23 24 using System.Collections; 24 25 using System.Collections.Generic; … … 55 56 56 57 public ItemSet() : base() { } 57 public ItemSet(IEnumerable<T> collection) : base(collection) { } 58 public ItemSet(IEnumerable<T> collection) : base(collection) { 59 foreach (T item in this) 60 item.Changed += new ChangedEventHandler(Item_Changed); 61 } 58 62 59 63 public object Clone() { … … 61 65 } 62 66 63 public IDeepCloneable Clone(Cloner cloner) { 64 List<T> items = new List<T>(); 65 foreach (T item in this) 66 items.Add((T)cloner.Clone(item)); 67 ItemSet<T> clone = (ItemSet<T>)Activator.CreateInstance(this.GetType(), items); 67 public virtual IDeepCloneable Clone(Cloner cloner) { 68 ItemSet<T> clone = (ItemSet<T>)Activator.CreateInstance(this.GetType(), this.Select(x => (T)cloner.Clone(x))); 68 69 cloner.RegisterClonedObject(this, clone); 69 70 return clone; -
trunk/sources/HeuristicLab.Core/3.3/NamedItem.cs
r2793 r2830 74 74 /// </summary> 75 75 protected NamedItem() { 76 name = ItemName;77 description = ItemDescription;76 name = string.Empty; 77 description = string.Empty; 78 78 } 79 79 /// <summary> … … 83 83 /// <param name="name">The name of the current instance.</param> 84 84 /// <param name="value">The value of the current instance.</param> 85 protected NamedItem(string name) 86 : this() { 85 protected NamedItem(string name) { 87 86 if (name == null) throw new ArgumentNullException(); 88 87 this.name = name; 88 description = string.Empty; 89 89 } 90 protected NamedItem(string name, string description) 91 : this(name) { 90 protected NamedItem(string name, string description) { 91 if (name == null) throw new ArgumentNullException(); 92 this.name = name; 92 93 this.description = description; 93 94 } -
trunk/sources/HeuristicLab.Core/3.3/NamedItemCollection.cs
r2790 r2830 21 21 22 22 using System; 23 using System.Linq; 23 24 using System.Collections.Generic; 24 25 using System.Drawing; … … 43 44 private object RestoreEvents { 44 45 get { return null; } 45 set { 46 foreach (T item in this) { 47 item.NameChanging += new EventHandler<CancelEventArgs<string>>(Item_NameChanging); 48 item.NameChanged += new EventHandler(Item_NameChanged); 49 item.Changed += new ChangedEventHandler(Item_Changed); 50 } 51 } 46 set { RegisterItemEvents(this); } 52 47 } 53 48 54 49 public NamedItemCollection() : base() { } 55 50 public NamedItemCollection(int capacity) : base(capacity) { } 56 public NamedItemCollection(IEnumerable<T> collection) : base(collection) { } 51 public NamedItemCollection(IEnumerable<T> collection) : base(collection) { 52 RegisterItemEvents(this); 53 } 57 54 58 55 public object Clone() { 59 56 return Clone(new Cloner()); 60 57 } 61 public IDeepCloneable Clone(Cloner cloner) { 62 List<T> items = new List<T>(); 63 foreach (T item in this) 64 items.Add((T)cloner.Clone(item)); 65 NamedItemCollection<T> clone = (NamedItemCollection<T>)Activator.CreateInstance(this.GetType(), items); 58 public virtual IDeepCloneable Clone(Cloner cloner) { 59 NamedItemCollection<T> clone = (NamedItemCollection<T>)Activator.CreateInstance(this.GetType(), this.Select(x => (T)cloner.Clone(x))); 66 60 cloner.RegisterClonedObject(this, clone); 67 61 return clone; … … 86 80 87 81 protected override void OnItemsAdded(IEnumerable<T> items) { 88 foreach (T item in items) { 89 item.NameChanging += new EventHandler<CancelEventArgs<string>>(Item_NameChanging); 90 item.NameChanged += new EventHandler(Item_NameChanged); 91 item.Changed += new ChangedEventHandler(Item_Changed); 92 } 82 RegisterItemEvents(items); 93 83 base.OnItemsAdded(items); 94 84 } 95 85 protected override void OnItemsRemoved(IEnumerable<T> items) { 96 foreach (T item in items) { 97 item.NameChanging -= new EventHandler<CancelEventArgs<string>>(Item_NameChanging); 98 item.NameChanged -= new EventHandler(Item_NameChanged); 99 item.Changed -= new ChangedEventHandler(Item_Changed); 100 } 86 DeregisterItemEvents(items); 101 87 base.OnItemsRemoved(items); 102 88 } … … 108 94 #endregion 109 95 protected override void OnCollectionReset(IEnumerable<T> items, IEnumerable<T> oldItems) { 110 foreach (T oldItem in oldItems) { 111 oldItem.NameChanging -= new EventHandler<CancelEventArgs<string>>(Item_NameChanging); 112 oldItem.NameChanged -= new EventHandler(Item_NameChanged); 113 oldItem.Changed -= new ChangedEventHandler(Item_Changed); 114 } 96 DeregisterItemEvents(oldItems); 97 RegisterItemEvents(items); 98 base.OnCollectionReset(items, oldItems); 99 } 100 protected override void OnPropertyChanged(string propertyName) { 101 base.OnPropertyChanged(propertyName); 102 OnChanged(); 103 } 104 105 private void RegisterItemEvents(IEnumerable<T> items) { 115 106 foreach (T item in items) { 116 107 item.NameChanging += new EventHandler<CancelEventArgs<string>>(Item_NameChanging); … … 118 109 item.Changed += new ChangedEventHandler(Item_Changed); 119 110 } 120 base.OnCollectionReset(items, oldItems);121 111 } 122 protected override void OnPropertyChanged(string propertyName) { 123 base.OnPropertyChanged(propertyName); 124 OnChanged(); 112 private void DeregisterItemEvents(IEnumerable<T> items) { 113 foreach (T item in items) { 114 item.NameChanging -= new EventHandler<CancelEventArgs<string>>(Item_NameChanging); 115 item.NameChanged -= new EventHandler(Item_NameChanged); 116 item.Changed -= new ChangedEventHandler(Item_Changed); 117 } 125 118 } 126 119 -
trunk/sources/HeuristicLab.Core/3.3/Scope.cs
r2790 r2830 20 20 #endregion 21 21 22 using System; 23 using System.Collections.Generic; 24 using System.Text; 25 using System.Xml; 22 using HeuristicLab.Collections; 26 23 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 27 using HeuristicLab.Collections;28 24 29 25 namespace HeuristicLab.Core { … … 99 95 clone.Name = Name; 100 96 clone.Description = Description; 101 clone.parent = (IScope)cloner.Clone(parent); 102 clone.Variables = (VariableCollection)cloner.Clone(variables); 103 clone.SubScopes = (ScopeList)cloner.Clone(subScopes); 97 if (variables.Count > 0) clone.Variables = (VariableCollection)cloner.Clone(variables); 98 if (subScopes.Count > 0) clone.SubScopes = (ScopeList)cloner.Clone(subScopes); 104 99 return clone; 105 100 } -
trunk/sources/HeuristicLab.Core/3.3/ScopeList.cs
r2790 r2830 20 20 #endregion 21 21 22 using System;23 using System.Collections;24 22 using System.Collections.Generic; 25 using System.Collections.ObjectModel; 26 using System.Text; 27 using System.Drawing; 23 using System.Linq; 28 24 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 29 using HeuristicLab.Common.Resources;30 using HeuristicLab.Collections;31 25 32 26 namespace HeuristicLab.Core { … … 34 28 [Item("ScopeList", "Represents a list of scopes.")] 35 29 [Creatable("Test")] 36 public class ScopeList : ItemList<IScope> {30 public sealed class ScopeList : ItemList<IScope> { 37 31 public ScopeList() : base() { } 38 32 public ScopeList(int capacity) : base(capacity) { } 39 33 public ScopeList(IEnumerable<IScope> collection) : base(collection) { } 34 35 public override IDeepCloneable Clone(Cloner cloner) { 36 ScopeList clone = new ScopeList(this.Select(x => (IScope)cloner.Clone(x))); 37 cloner.RegisterClonedObject(this, clone); 38 return clone; 39 } 40 40 } 41 41 } -
trunk/sources/HeuristicLab.Core/3.3/Variable.cs
r2818 r2830 53 53 public Variable() 54 54 : base("Anonymous") { 55 Value = null;55 this.value = null; 56 56 } 57 57 /// <summary> … … 61 61 /// <param name="name">The name of the current instance.</param> 62 62 /// <param name="value">The value of the current instance.</param> 63 public Variable(string name) 64 : base(name) { 65 this.value = null; 66 } 67 public Variable(string name, string description) 68 : base(name, description) { 69 this.value = null; 70 } 63 71 public Variable(string name, IItem value) 64 72 : base(name) { 65 Value = value; 73 this.value = value; 74 this.value.Changed += new ChangedEventHandler(Value_Changed); 75 } 76 public Variable(string name, string description, IItem value) 77 : base(name, description) { 78 this.value = value; 79 this.value.Changed += new ChangedEventHandler(Value_Changed); 66 80 } 67 81 … … 72 86 /// <returns>The cloned object as <see cref="Variable"/>.</returns> 73 87 public override IDeepCloneable Clone(Cloner cloner) { 74 Variable clone = new Variable( );88 Variable clone = new Variable(Name, Description, (IItem)cloner.Clone(value)); 75 89 cloner.RegisterClonedObject(this, clone); 76 clone.Name = Name;77 clone.Description = Description;78 clone.Value = (IItem)cloner.Clone(value);79 90 return clone; 80 91 } -
trunk/sources/HeuristicLab.Core/3.3/VariableCollection.cs
r2790 r2830 21 21 22 22 using System.Collections.Generic; 23 using System.Linq; 23 24 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 24 25 … … 27 28 [Item("VariableCollection", "Represents a collection of variables.")] 28 29 [Creatable("Test")] 29 public class VariableCollection : NamedItemCollection<IVariable> {30 public sealed class VariableCollection : NamedItemCollection<IVariable> { 30 31 public VariableCollection() : base() { } 31 32 public VariableCollection(int capacity) : base(capacity) { } 32 33 public VariableCollection(IEnumerable<IVariable> collection) : base(collection) { } 34 35 public override IDeepCloneable Clone(Cloner cloner) { 36 VariableCollection clone = new VariableCollection(this.Select(x => (IVariable)cloner.Clone(x))); 37 cloner.RegisterClonedObject(this, clone); 38 return clone; 39 } 33 40 } 34 41 }
Note: See TracChangeset
for help on using the changeset viewer.