Free cookie consent management tool by TermsFeed Policy Generator

Changeset 3935


Ignore:
Timestamp:
06/21/10 15:58:31 (14 years ago)
Author:
epitzer
Message:

Add EasyXmlGenerator for easier review of generated XML. (#1139)

Location:
trunk/sources/HeuristicLab.Persistence/3.3
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Persistence/3.3/Auxiliary/TypeName.cs

    r3903 r3935  
    176176        sb.Append(">");
    177177      }
     178      sb.Append(MemoryMagic);
     179      return sb.ToString();
     180    }
     181
     182    public string GetTypeNameInCode(bool includeAllNamespaces) {
     183      StringBuilder sb = new StringBuilder();
     184      if (includeAllNamespaces)
     185        sb.Append(Namespace).Append('.');
     186      sb.Append(ClassName);
     187      if (IsGeneric) {
     188        sb.Append("<");
     189        sb.Append(
     190          string.Join(", ",
     191            GenericArgs
     192              .Select(a => a.GetTypeNameInCode(includeAllNamespaces))
     193              .ToArray()));
     194        sb.Append(">");
     195      }
     196      sb.Append(MemoryMagic);
    178197      return sb.ToString();
    179198    }
  • trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/XmlGenerator.cs

    r3742 r3935  
    4040  public class XmlGenerator : GeneratorBase<string> {
    4141
    42     private int depth;
    43     private int Depth {
     42    protected int depth;
     43    protected int Depth {
    4444      get {
    4545        return depth;
     
    5151    }
    5252
    53     private string prefix;
     53    protected string prefix;
    5454
    5555
     
    6161    }
    6262
    63     private enum NodeType { Start, End, Inline } ;
    64 
    65     private static void AddXmlTagContent(StringBuilder sb, string name, Dictionary<string, object> attributes) {
     63    protected enum NodeType { Start, End, Inline } ;
     64
     65    protected static void AddXmlTagContent(StringBuilder sb, string name, Dictionary<string, object> attributes) {
    6666      sb.Append(name);
    6767      foreach (var attribute in attributes) {
     
    7676    }
    7777
    78     private static void AddXmlStartTag(StringBuilder sb, string name, Dictionary<string, object> attributes) {
     78    protected static void AddXmlStartTag(StringBuilder sb, string name, Dictionary<string, object> attributes) {
    7979      sb.Append('<');
    8080      AddXmlTagContent(sb, name, attributes);
     
    8282    }
    8383
    84     private static void AddXmlInlineTag(StringBuilder sb, string name, Dictionary<string, object> attributes) {
     84    protected static void AddXmlInlineTag(StringBuilder sb, string name, Dictionary<string, object> attributes) {
    8585      sb.Append('<');
    8686      AddXmlTagContent(sb, name, attributes);
     
    8888    }
    8989
    90     private static void AddXmlEndTag(StringBuilder sb, string name) {
     90    protected static void AddXmlEndTag(StringBuilder sb, string name) {
    9191      sb.Append("</");
    9292      sb.Append(name);
     
    9494    }
    9595
    96     private string CreateNodeStart(string name, Dictionary<string, object> attributes) {
     96    protected string CreateNodeStart(string name, Dictionary<string, object> attributes) {
    9797      StringBuilder sb = new StringBuilder();
    9898      sb.Append(prefix);
     
    103103    }
    104104
    105     private string CreateNodeStart(string name) {
     105    protected string CreateNodeStart(string name) {
    106106      return CreateNodeStart(name, new Dictionary<string, object>());
    107107    }
    108108
    109     private string CreateNodeEnd(string name) {
     109    protected string CreateNodeEnd(string name) {
    110110      Depth -= 1;
    111111      StringBuilder sb = new StringBuilder();
     
    116116    }
    117117
    118     private string CreateNode(string name, Dictionary<string, object> attributes) {
     118    protected string CreateNode(string name, Dictionary<string, object> attributes) {
    119119      StringBuilder sb = new StringBuilder();
    120120      sb.Append(prefix);
     
    124124    }
    125125
    126     private string CreateNode(string name, Dictionary<string, object> attributes, string content) {
     126    protected string CreateNode(string name, Dictionary<string, object> attributes, string content) {
    127127      StringBuilder sb = new StringBuilder();
    128128      sb.Append(prefix);
     
    148148    }
    149149
    150     private void AddTypeInfo(int typeId, Dictionary<string, object> dict) {
     150    protected void AddTypeInfo(int typeId, Dictionary<string, object> dict) {
    151151      if (lastTypeToken != null) {
    152152        if (typeId == lastTypeToken.Id) {
     
    225225    }
    226226
    227     private TypeToken lastTypeToken;
     227    protected TypeToken lastTypeToken;
    228228    /// <summary>
    229229    /// Formats the specified token.
     
    236236    }
    237237
    238     private string FlushTypeToken() {
     238    protected string FlushTypeToken() {
    239239      if (lastTypeToken == null)
    240240        return "";
  • trunk/sources/HeuristicLab.Persistence/3.3/HeuristicLab.Persistence-3.3.csproj

    r3832 r3935  
    158158    <Compile Include="Default\Xml\Compact\NumberArray2XmlSerializerBase.cs" />
    159159    <Compile Include="Default\Xml\Compact\NumberEnumeration2XmlSerializerBase.cs" />
     160    <Compile Include="Default\Xml\EasyXmlGenerator.cs" />
    160161    <Compile Include="Default\Xml\Primitive\System.Drawing\Bitmap2XmlSerializer.cs" />
    161162    <Compile Include="Default\Xml\Primitive\Bool2XmlSerializer.cs" />
  • trunk/sources/HeuristicLab.Persistence/3.3/Tests/UseCases.cs

    r3811 r3935  
    4242namespace HeuristicLab.Persistence_33.Tests {
    4343
    44   [StorableClass] 
     44  [StorableClass]
    4545  public class NumberTest {
    4646    [Storable]
     
    288288      Root newR = (Root)XmlParser.Deserialize(tempFile);
    289289      CompareComplexStorables(r, newR);
     290    }
     291
     292    [TestMethod]
     293    public void ComplexEasyStorable() {
     294      Root r = InitializeComplexStorable();
     295      ReadableXmlGenerator.Serialize(r, tempFile);
     296      using (var reader = new StreamReader(tempFile)) {
     297        string text = reader.ReadToEnd();
     298        Assert.IsTrue(text.StartsWith("<Root"));
     299      }
    290300    }
    291301
     
    774784
    775785      Assert.AreEqual(bitmap.Size, newBitmap.Size);
    776       for(int i=0; i< bitmap.Size.Width; i++)
    777         for(int j =0; j< bitmap.Size.Height; j++)
    778           Assert.AreEqual(bitmap.GetPixel(i,j),newBitmap.GetPixel(i,j));
     786      for (int i = 0; i < bitmap.Size.Width; i++)
     787        for (int j = 0; j < bitmap.Size.Height; j++)
     788          Assert.AreEqual(bitmap.GetPixel(i, j), newBitmap.GetPixel(i, j));
    779789    }
    780790
     
    813823      Assert.IsFalse(newHookTest.WasSerialized);
    814824    }
    815    
     825
    816826    [StorableClass]
    817827    private class CustomConstructor {
     
    858868
    859869    [TestMethod]
    860     public void TestRejectionJustifications() { 
     870    public void TestRejectionJustifications() {
    861871      NonSerializable ns = new NonSerializable();
    862872      try {
     
    864874        Assert.Fail("PersistenceException expected");
    865875      } catch (PersistenceException x) {
    866         Assert.IsTrue(x.Message.Contains(new StorableSerializer().JustifyRejection(typeof(NonSerializable))));       
     876        Assert.IsTrue(x.Message.Contains(new StorableSerializer().JustifyRejection(typeof(NonSerializable))));
    867877      }
    868878    }
     
    967977      Assert.AreEqual(afs.Value3, newAfs.Value3);
    968978      Assert.AreEqual(afs.Value4, newAfs.Value4);
    969      
     979
    970980    }
    971981
     
    9961006      Assert.AreEqual(afs.Value2, newAfs.Value2);
    9971007      Assert.AreEqual(afs.Value3, newAfs.Value3);
    998       Assert.AreEqual(afs.Value4, newAfs.Value4);     
     1008      Assert.AreEqual(afs.Value4, newAfs.Value4);
    9991009    }
    10001010
     
    10221032      XmlGenerator.Serialize(afs, tempFile);
    10231033      MarkedOnlyStorable newAfs = (MarkedOnlyStorable)XmlParser.Deserialize(tempFile);
    1024       Assert.AreEqual(1, newAfs.Value1);     
     1034      Assert.AreEqual(1, newAfs.Value1);
    10251035      Assert.AreEqual(afs.Value2, newAfs.Value2);
    10261036      Assert.AreEqual(0, newAfs.Value3);
     
    10541064      Assert.IsTrue(double.IsNaN(newSpecials[2]));
    10551065    }
    1056    
     1066
    10571067
    10581068    [ClassInitialize]
Note: See TracChangeset for help on using the changeset viewer.