Changeset 6876
- Timestamp:
- 10/05/11 21:30:50 (13 years ago)
- Location:
- branches/GeneralizedQAP
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GeneralizedQAP/HeuristicLab.Common/3.3/ObjectExtensions.cs
r6500 r6876 30 30 namespace HeuristicLab.Common { 31 31 public static class ObjectExtensions { 32 public static IEnumerable<object> GetObjectGraphObjects(this object obj ) {32 public static IEnumerable<object> GetObjectGraphObjects(this object obj, bool excludeStaticMembers = false) { 33 33 if (obj == null) return Enumerable.Empty<object>(); 34 34 … … 41 41 objects.Add(current); 42 42 43 foreach (object o in GetChildObjects(current )) {43 foreach (object o in GetChildObjects(current, excludeStaticMembers)) { 44 44 if (o != null && !objects.Contains(o) && !ExcludeType(o.GetType())) 45 45 stack.Push(o); … … 49 49 return objects; 50 50 } 51 51 52 /// <summary> 52 53 /// Types not collected: … … 68 69 (type.HasElementType && ExcludeType(type.GetElementType())); 69 70 } 70 private static IEnumerable<object> GetChildObjects(object obj ) {71 private static IEnumerable<object> GetChildObjects(object obj, bool excludeStaticMembers) { 71 72 Type type = obj.GetType(); 72 73 … … 93 94 } else { 94 95 foreach (FieldInfo f in type.GetAllFields()) { 96 if (excludeStaticMembers && f.IsStatic) continue; 95 97 yield return f.GetValue(obj); 96 98 } -
branches/GeneralizedQAP/HeuristicLab/3.3/Tests/DeepCloneableCloningTest.cs
r6685 r6876 23 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using System.Threading;26 25 using HeuristicLab.Common; 27 26 using HeuristicLab.Core; … … 82 81 #endregion 83 82 84 private ManualResetEvent waitHandle;85 86 83 [TestMethod] 87 84 [DeploymentItem("SamplesExperimentFinished.hl")] 88 85 public void TestCloningFinishedExperiment() { 89 waitHandle = new ManualResetEvent(false);90 86 Experiment experiment = (Experiment)XmlParser.Deserialize("SamplesExperimentFinished.hl"); 91 87 … … 94 90 95 91 Assert.IsTrue(ProcessEqualObjects(experiment, intersections)); 96 }97 98 private void batchrun_Stopped(object sender, EventArgs e) {99 waitHandle.Set();100 92 } 101 93 … … 114 106 IDeepCloneable item = null; 115 107 try { 116 item = (IDeepCloneable)Activator.CreateInstance(deepCloneableType, nonPublic: true);108 item = (IDeepCloneable)Activator.CreateInstance(deepCloneableType, nonPublic: false); 117 109 } catch { continue; } // no default constructor 118 110 … … 128 120 129 121 private IEnumerable<object> CheckTotalInequality(object original, object clone) { 130 HashSet<object> originalObjects = new HashSet<object>(original.GetObjectGraphObjects( ).Where(x => !x.GetType().IsValueType), new ReferenceEqualityComparer());131 HashSet<object> clonedObjects = new HashSet<object>(clone.GetObjectGraphObjects( ).Where(x => !x.GetType().IsValueType), new ReferenceEqualityComparer());122 HashSet<object> originalObjects = new HashSet<object>(original.GetObjectGraphObjects(true).Where(x => !x.GetType().IsValueType), new ReferenceEqualityComparer()); 123 HashSet<object> clonedObjects = new HashSet<object>(clone.GetObjectGraphObjects(true).Where(x => !x.GetType().IsValueType), new ReferenceEqualityComparer()); 132 124 133 125 return originalObjects.Intersect(clonedObjects);
Note: See TracChangeset
for help on using the changeset viewer.