Free cookie consent management tool by TermsFeed Policy Generator

Changeset 6876


Ignore:
Timestamp:
10/05/11 21:30:50 (13 years ago)
Author:
abeham
Message:

#1628

  • excluded static fields
  • excluded types with private default constructor
Location:
branches/GeneralizedQAP
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/GeneralizedQAP/HeuristicLab.Common/3.3/ObjectExtensions.cs

    r6500 r6876  
    3030namespace HeuristicLab.Common {
    3131  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) {
    3333      if (obj == null) return Enumerable.Empty<object>();
    3434
     
    4141        objects.Add(current);
    4242
    43         foreach (object o in GetChildObjects(current)) {
     43        foreach (object o in GetChildObjects(current, excludeStaticMembers)) {
    4444          if (o != null && !objects.Contains(o) && !ExcludeType(o.GetType()))
    4545            stack.Push(o);
     
    4949      return objects;
    5050    }
     51
    5152    /// <summary>
    5253    /// Types not collected:
     
    6869             (type.HasElementType && ExcludeType(type.GetElementType()));
    6970    }
    70     private static IEnumerable<object> GetChildObjects(object obj) {
     71    private static IEnumerable<object> GetChildObjects(object obj, bool excludeStaticMembers) {
    7172      Type type = obj.GetType();
    7273
     
    9394      } else {
    9495        foreach (FieldInfo f in type.GetAllFields()) {
     96          if (excludeStaticMembers && f.IsStatic) continue;
    9597          yield return f.GetValue(obj);
    9698        }
  • branches/GeneralizedQAP/HeuristicLab/3.3/Tests/DeepCloneableCloningTest.cs

    r6685 r6876  
    2323using System.Collections.Generic;
    2424using System.Linq;
    25 using System.Threading;
    2625using HeuristicLab.Common;
    2726using HeuristicLab.Core;
     
    8281    #endregion
    8382
    84     private ManualResetEvent waitHandle;
    85 
    8683    [TestMethod]
    8784    [DeploymentItem("SamplesExperimentFinished.hl")]
    8885    public void TestCloningFinishedExperiment() {
    89       waitHandle = new ManualResetEvent(false);
    9086      Experiment experiment = (Experiment)XmlParser.Deserialize("SamplesExperimentFinished.hl");
    9187
     
    9490
    9591      Assert.IsTrue(ProcessEqualObjects(experiment, intersections));
    96     }
    97 
    98     private void batchrun_Stopped(object sender, EventArgs e) {
    99       waitHandle.Set();
    10092    }
    10193
     
    114106        IDeepCloneable item = null;
    115107        try {
    116           item = (IDeepCloneable)Activator.CreateInstance(deepCloneableType, nonPublic: true);
     108          item = (IDeepCloneable)Activator.CreateInstance(deepCloneableType, nonPublic: false);
    117109        } catch { continue; } // no default constructor
    118110
     
    128120
    129121    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());
    132124
    133125      return originalObjects.Intersect(clonedObjects);
Note: See TracChangeset for help on using the changeset viewer.