Free cookie consent management tool by TermsFeed Policy Generator

Changeset 1684


Ignore:
Timestamp:
04/28/09 13:58:49 (16 years ago)
Author:
epitzer
Message:

Fix EnumDecomposer to be applicable for flag enums and enums without names. (#603)

Location:
trunk/sources/HeuristicLab.Persistence
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Persistence/3.3/Default/Decomposers/EnumDecomposer.cs

    r1625 r1684  
    1919
    2020    public IEnumerable<Tag> CreateMetaInfo(object obj) {
    21       yield return new Tag(Enum.GetName(obj.GetType(), obj));
     21      yield return new Tag(Enum.Format(obj.GetType(), obj, "G"));
    2222    }
    2323
  • trunk/sources/HeuristicLab.Persistence/UnitTests/UseCases.cs

    r1683 r1684  
    100100    [Storable(DefaultValue = "default")]
    101101    public string uninitialized;
     102  }
     103
     104  public enum SimpleEnum { one, two, three }
     105  public enum ComplexEnum { one = 1, two = 2, three = 3 }
     106  [FlagsAttribute]
     107  public enum TrickyEnum { zero = 0, one = 1, two = 2 }
     108
     109  public class EnumTest {
     110    [Storable]
     111    public SimpleEnum simpleEnum = SimpleEnum.one;
     112    [Storable]
     113    public ComplexEnum complexEnum = (ComplexEnum)2;
     114    [Storable]
     115    public TrickyEnum trickyEnum = (TrickyEnum)15;
    102116  }
    103117
     
    422436    }
    423437
     438    [TestMethod]
     439    public void Enums() {
     440      EnumTest et = new EnumTest();
     441      et.simpleEnum = SimpleEnum.two;
     442      et.complexEnum = ComplexEnum.three;
     443      et.trickyEnum = TrickyEnum.two | TrickyEnum.one;
     444      XmlGenerator.Serialize(et, tempFile);
     445      EnumTest newEt = (EnumTest)XmlParser.DeSerialize(tempFile);
     446      Assert.AreEqual(et.simpleEnum, SimpleEnum.two);
     447      Assert.AreEqual(et.complexEnum, ComplexEnum.three);
     448      Assert.AreEqual(et.trickyEnum, (TrickyEnum)3);
     449    }
     450
    424451
    425452    [ClassInitialize]
Note: See TracChangeset for help on using the changeset viewer.