- Timestamp:
- 06/21/10 18:46:04 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/XmlGenerator.cs
r3935 r3937 23 23 using System; 24 24 using System.Text; 25 using System.Linq; 25 26 using HeuristicLab.Persistence.Interfaces; 26 27 using HeuristicLab.Persistence.Core; … … 63 64 protected enum NodeType { Start, End, Inline } ; 64 65 65 protected static void AddXmlTagContent(StringBuilder sb, string name, Dictionary<string, object> attributes) {66 protected static void AddXmlTagContent(StringBuilder sb, string name, Dictionary<string, string> attributes) { 66 67 sb.Append(name); 67 68 foreach (var attribute in attributes) { … … 76 77 } 77 78 78 protected static void AddXmlStartTag(StringBuilder sb, string name, Dictionary<string, object> attributes) { 79 protected static int AttributeLength(Dictionary<string, string> attributes) { 80 return attributes 81 .Where(kvp => !string.IsNullOrEmpty(kvp.Key) && !string.IsNullOrEmpty(kvp.Value)) 82 .Select(kvp => kvp.Key.Length + kvp.Value.Length + 4).Sum(); 83 } 84 85 protected static void AddXmlStartTag(StringBuilder sb, string name, Dictionary<string, string> attributes) { 79 86 sb.Append('<'); 80 87 AddXmlTagContent(sb, name, attributes); … … 82 89 } 83 90 84 protected static void AddXmlInlineTag(StringBuilder sb, string name, Dictionary<string, object> attributes) {91 protected static void AddXmlInlineTag(StringBuilder sb, string name, Dictionary<string, string> attributes) { 85 92 sb.Append('<'); 86 93 AddXmlTagContent(sb, name, attributes); … … 94 101 } 95 102 96 protected string CreateNodeStart(string name, Dictionary<string, object> attributes) { 97 StringBuilder sb = new StringBuilder(); 103 protected string CreateNodeStart(string name, Dictionary<string, string> attributes) { 104 StringBuilder sb = new StringBuilder(prefix.Length + name.Length + 4 105 + AttributeLength(attributes)); 98 106 sb.Append(prefix); 99 107 Depth += 1; … … 103 111 } 104 112 113 private static Dictionary<string, string> emptyDict = new Dictionary<string, string>(); 105 114 protected string CreateNodeStart(string name) { 106 return CreateNodeStart(name, new Dictionary<string, object>());115 return CreateNodeStart(name, emptyDict); 107 116 } 108 117 109 118 protected string CreateNodeEnd(string name) { 110 119 Depth -= 1; 111 StringBuilder sb = new StringBuilder( );120 StringBuilder sb = new StringBuilder(prefix.Length + name.Length + 5); 112 121 sb.Append(prefix); 113 122 AddXmlEndTag(sb, name); … … 116 125 } 117 126 118 protected string CreateNode(string name, Dictionary<string, object> attributes) { 119 StringBuilder sb = new StringBuilder(); 127 protected string CreateNode(string name, Dictionary<string, string> attributes) { 128 StringBuilder sb = new StringBuilder(prefix.Length + name.Length + 5 129 + AttributeLength(attributes)); 120 130 sb.Append(prefix); 121 131 AddXmlInlineTag(sb, name, attributes); … … 124 134 } 125 135 126 protected string CreateNode(string name, Dictionary<string, object> attributes, string content) {136 protected string CreateNode(string name, Dictionary<string, string> attributes, string content) { 127 137 StringBuilder sb = new StringBuilder(); 128 138 sb.Append(prefix); … … 139 149 /// <returns>The token in serialized form.</returns> 140 150 protected override string Format(BeginToken beginToken) { 141 var dict = new Dictionary<string, object> {151 var dict = new Dictionary<string, string> { 142 152 {"name", beginToken.Name}, 143 {"typeId", beginToken.TypeId },144 {"id", beginToken.Id }};153 {"typeId", beginToken.TypeId.ToString()}, 154 {"id", beginToken.Id.ToString()}}; 145 155 AddTypeInfo(beginToken.TypeId, dict); 146 156 return CreateNodeStart(XmlStringConstants.COMPOSITE, dict); … … 148 158 } 149 159 150 protected void AddTypeInfo(int typeId, Dictionary<string, object> dict) {160 protected void AddTypeInfo(int typeId, Dictionary<string, string> dict) { 151 161 if (lastTypeToken != null) { 152 162 if (typeId == lastTypeToken.Id) { … … 175 185 /// <returns>The token in serialized form.</returns> 176 186 protected override string Format(PrimitiveToken dataToken) { 177 var dict = new Dictionary<string, object> {178 {"typeId", dataToken.TypeId },187 var dict = new Dictionary<string, string> { 188 {"typeId", dataToken.TypeId.ToString()}, 179 189 {"name", dataToken.Name}, 180 {"id", dataToken.Id }};190 {"id", dataToken.Id.ToString()}}; 181 191 AddTypeInfo(dataToken.TypeId, dict); 182 192 return CreateNode(XmlStringConstants.PRIMITIVE, dict, … … 191 201 protected override string Format(ReferenceToken refToken) { 192 202 return CreateNode(XmlStringConstants.REFERENCE, 193 new Dictionary<string, object> {194 {"ref", refToken.Id },203 new Dictionary<string, string> { 204 {"ref", refToken.Id.ToString()}, 195 205 {"name", refToken.Name}}); 196 206 } … … 203 213 protected override string Format(NullReferenceToken nullRefToken) { 204 214 return CreateNode(XmlStringConstants.NULL, 205 new Dictionary<string, object>{215 new Dictionary<string, string>{ 206 216 {"name", nullRefToken.Name}}); 207 217 } … … 241 251 try { 242 252 return CreateNode(XmlStringConstants.TYPE, 243 new Dictionary<string, object> {244 {"id", lastTypeToken.Id },253 new Dictionary<string, string> { 254 {"id", lastTypeToken.Id.ToString()}, 245 255 {"typeName", lastTypeToken.TypeName }, 246 256 {"serializer", lastTypeToken.Serializer }});
Note: See TracChangeset
for help on using the changeset viewer.