- Timestamp:
- 04/08/09 17:05:17 (15 years ago)
- Location:
- trunk/sources/HeuristicLab.Persistence/3.3/Default/Decomposers
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Persistence/3.3/Default/Decomposers/ArrayDecomposer.cs
r1539 r1542 16 16 } 17 17 18 public IEnumerable<Tag> De Compose(object array) {18 public IEnumerable<Tag> Decompose(object array) { 19 19 Array a = (Array)array; 20 20 yield return new Tag("rank", a.Rank); -
trunk/sources/HeuristicLab.Persistence/3.3/Default/Decomposers/DictionaryDecomposer.cs
r1539 r1542 23 23 key = v; 24 24 keyIsSet = true; 25 check();25 Check(); 26 26 } 27 27 … … 29 29 value = v; 30 30 valueIsSet = true; 31 check();31 Check(); 32 32 } 33 33 34 private void check() {34 private void Check() { 35 35 if ( keyIsSet && valueIsSet ) 36 36 dict.Add(key, value); … … 50 50 } 51 51 52 public IEnumerable<Tag> De Compose(object o) {52 public IEnumerable<Tag> Decompose(object o) { 53 53 IDictionary dict = (IDictionary)o; 54 54 foreach ( DictionaryEntry entry in dict) { -
trunk/sources/HeuristicLab.Persistence/3.3/Default/Decomposers/EnumDecomposer.cs
r1539 r1542 13 13 14 14 public bool CanDecompose(Type type) { 15 return type.IsEnum || type == typeof 15 return type.IsEnum || type == typeof(Enum); 16 16 } 17 17 18 public IEnumerable<Tag> De Compose(object obj) {18 public IEnumerable<Tag> Decompose(object obj) { 19 19 yield return new Tag(Enum.GetName(obj.GetType(), obj)); 20 20 } -
trunk/sources/HeuristicLab.Persistence/3.3/Default/Decomposers/EnumerableDecomposer.cs
r1539 r1542 68 68 } 69 69 70 public IEnumerable<Tag> De Compose(object obj) {70 public IEnumerable<Tag> Decompose(object obj) { 71 71 foreach (object o in (IEnumerable)obj) { 72 72 yield return new Tag(null, o); -
trunk/sources/HeuristicLab.Persistence/3.3/Default/Decomposers/KeyValuePairDecomposer.cs
r1539 r1542 21 21 } 22 22 23 public IEnumerable<Tag> De Compose(object o) {23 public IEnumerable<Tag> Decompose(object o) { 24 24 Type t = o.GetType(); 25 25 yield return new Tag("key", t.GetProperty("Key").GetValue(o, null)); -
trunk/sources/HeuristicLab.Persistence/3.3/Default/Decomposers/StorableDecomposer.cs
r1539 r1542 19 19 } 20 20 21 public IEnumerable<Tag> De Compose(object obj) {21 public IEnumerable<Tag> Decompose(object obj) { 22 22 foreach (var mapping in StorableAttribute.GetAutostorableAccessors(obj)) { 23 23 yield return new Tag(mapping.Key, mapping.Value.Get()); -
trunk/sources/HeuristicLab.Persistence/3.3/Default/Decomposers/TypeDecomposer.cs
r1539 r1542 17 17 } 18 18 19 public IEnumerable<Tag> De Compose(object obj) {19 public IEnumerable<Tag> Decompose(object obj) { 20 20 Type t = (Type) obj; 21 21 yield return new Tag("VersionInvariantName", t.VersionInvariantName()); -
trunk/sources/HeuristicLab.Persistence/3.3/Default/Decomposers/X2StringDecomposer.cs
r1539 r1542 9 9 namespace HeuristicLab.Persistence.Default.Decomposers { 10 10 11 public class Number2StringDecomposer : IDecomposer { 12 13 public int Priority { 14 get { return 100; } 15 } 16 11 public class Number2StringConverter { 17 12 18 13 private static readonly List<Type> numberTypes = … … 34 29 private static readonly Dictionary<Type, MethodInfo> numberParsers; 35 30 36 static Number2String Decomposer() {31 static Number2StringConverter() { 37 32 numberParsers = new Dictionary<Type, MethodInfo>(); 38 33 foreach ( var type in numberTypes ) { … … 56 51 return obj.ToString(); 57 52 } 58 59 public IEnumerable<Tag> DeCompose(object obj) { 60 yield return new Tag(Format(obj)); 61 } 62 63 public object CreateInstance(Type type) { 64 return null; 65 } 66 53 67 54 public object Parse(string stringValue, Type type) { 68 55 return numberParsers[type] … … 72 59 } 73 60 74 public object Populate(object instance, IEnumerable<Tag> tags, Type type) {75 foreach (Tag tag in tags)76 return Parse((string)tag.Value, type);77 throw new ApplicationException("not enough tags to re-compose number.");78 }79 80 61 } 81 62 … … 91 72 } 92 73 93 public IEnumerable<Tag> De Compose(object obj) {74 public IEnumerable<Tag> Decompose(object obj) { 94 75 yield return new Tag(((DateTime)obj).Ticks); 95 76 } … … 114 95 } 115 96 116 private static readonly Number2String Decomposer numberDecomposer =117 new Number2String Decomposer();97 private static readonly Number2StringConverter numberConverter = 98 new Number2StringConverter(); 118 99 119 100 public bool CanDecompose(Type type) { 120 101 return 121 102 (type.IsArray || type == typeof (Array)) && 122 number Decomposer.CanDecompose(type.GetElementType());123 } 124 125 public IEnumerable<Tag> De Compose(object obj) {103 numberConverter.CanDecompose(type.GetElementType()); 104 } 105 106 public IEnumerable<Tag> Decompose(object obj) { 126 107 Array a = (Array) obj; 127 108 int[] lengths = new int[a.Rank]; … … 139 120 int[] positions = (int[])lowerBounds.Clone(); 140 121 while (positions[a.Rank - 1] < lengths[a.Rank - 1] + lowerBounds[a.Rank - 1]) { 141 sb.Append(number Decomposer.Format(a.GetValue(positions))).Append(';');122 sb.Append(numberConverter.Format(a.GetValue(positions))).Append(';'); 142 123 positions[0] += 1; 143 124 for (int i = 0; i < a.Rank - 1; i++) { … … 180 161 while (valueIter.MoveNext()) { 181 162 a.SetValue( 182 number Decomposer.Parse((string)valueIter.Current, elementType),163 numberConverter.Parse((string)valueIter.Current, elementType), 183 164 positions); 184 165 positions[0] += 1; … … 202 183 } 203 184 204 private static readonly Number2String Decomposer numberDecomposer =205 new Number2String Decomposer();185 private static readonly Number2StringConverter numberConverter = 186 new Number2StringConverter(); 206 187 207 188 private static readonly Dictionary<Type, Type> interfaceCache = new Dictionary<Type, Type>(); … … 213 194 if (iface.IsGenericType && 214 195 iface.GetGenericTypeDefinition() == typeof(IEnumerable<>) && 215 number Decomposer.CanDecompose(iface.GetGenericArguments()[0])) {196 numberConverter.CanDecompose(iface.GetGenericArguments()[0])) { 216 197 interfaceCache.Add(type, iface); 217 198 return iface; … … 243 224 } 244 225 245 public IEnumerable<Tag> De Compose(object obj) {226 public IEnumerable<Tag> Decompose(object obj) { 246 227 Type type = obj.GetType(); 247 228 Type enumerable = GetGenericEnumerableInterface(type); … … 259 240 while ( (bool)moveNextMethod.Invoke(genericEnumerator, empty) ) 260 241 sb.Append( 261 number Decomposer.Format(242 numberConverter.Format( 262 243 currentProperty.GetValue(genericEnumerator, null))).Append(';'); 263 244 yield return new Tag("compact enumerable", sb.ToString()); … … 277 258 .Split(new[] {';'}, StringSplitOptions.RemoveEmptyEntries); 278 259 foreach (var value in stringValues) { 279 addMethod.Invoke(instance, new[] {number Decomposer.Parse(value, elementType)});260 addMethod.Invoke(instance, new[] {numberConverter.Parse(value, elementType)}); 280 261 } 281 262 return instance;
Note: See TracChangeset
for help on using the changeset viewer.