Changeset 5290 for trunk/sources/HeuristicLab.Persistence/3.3/Default/CompositeSerializers/ConcreteDictionarySerializer.cs
- Timestamp:
- 01/13/11 13:01:28 (14 years ago)
- File:
-
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Persistence/3.3/Default/CompositeSerializers/ConcreteDictionarySerializer.cs
r5289 r5290 23 23 using System.Collections; 24 24 using System.Collections.Generic; 25 using HeuristicLab.Persistence.Auxiliary;25 using System.Linq; 26 26 using HeuristicLab.Persistence.Core; 27 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; … … 31 31 32 32 [StorableClass] 33 internal sealed class DictionarySerializer : ICompositeSerializer {33 internal sealed class ConcreteDictionarySerializer : ICompositeSerializer { 34 34 35 35 [StorableConstructor] 36 private DictionarySerializer(bool deserializing) { }37 public DictionarySerializer() { }36 private ConcreteDictionarySerializer(bool deserializing) { } 37 public ConcreteDictionarySerializer() { } 38 38 39 39 public int Priority { … … 43 43 44 44 public bool CanSerialize(Type type) { 45 return ReflectionTools.HasDefaultConstructor(type) && 46 type.GetInterface(typeof(IDictionary).FullName) != null; 45 return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Dictionary<,>); 47 46 } 48 47 49 48 public string JustifyRejection(Type type) { 50 if (!ReflectionTools.HasDefaultConstructor(type)) 51 return "no default constructor"; 52 return "interface IDictionary not implemented"; 49 return "Type is not a generic Dictionary<>"; 53 50 } 54 51 55 52 public IEnumerable<Tag> CreateMetaInfo(object o) { 56 return new Tag[] { };53 yield return new Tag("Comparer", o.GetType().GetProperty("Comparer").GetValue(o, null)); 57 54 } 58 55 … … 66 63 67 64 public object CreateInstance(Type t, IEnumerable<Tag> metaInfo) { 68 return Activator.CreateInstance(t, true);65 return Activator.CreateInstance(t, metaInfo.First().Value); 69 66 } 70 67 … … 79 76 dict.Add(key.Value, value.Value); 80 77 } 81 } 82 catch (InvalidOperationException e) { 78 } catch (InvalidOperationException e) { 83 79 throw new PersistenceException("Dictionaries must contain an even number of elements (key+value).", e); 84 } 85 catch (NotSupportedException e) { 80 } catch (NotSupportedException e) { 86 81 throw new PersistenceException("The serialized dictionary type was read-only or had a fixed size and cannot be deserialized.", e); 87 } 88 catch (ArgumentNullException e) { 82 } catch (ArgumentNullException e) { 89 83 throw new PersistenceException("Dictionary key was null.", e); 90 } 91 catch (ArgumentException e) { 84 } catch (ArgumentException e) { 92 85 throw new PersistenceException("Duplicate dictionary key.", e); 93 86 }
Note: See TracChangeset
for help on using the changeset viewer.