Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/29/09 15:32:59 (15 years ago)
Author:
epitzer
Message:

Check for default constructor in all decomposers to ensure failure during serialization instead of deserialization. (#606)

Location:
trunk/sources/HeuristicLab.Persistence/3.3/Default/Decomposers
Files:
4 edited

Legend:

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

    r1625 r1705  
    55using System.Collections.Generic;
    66using HeuristicLab.Persistence.Default.Decomposers.Storable;
     7using HeuristicLab.Persistence.Auxiliary;
    78
    89namespace HeuristicLab.Persistence.Default.Decomposers {
     
    1718
    1819    public bool CanDecompose(Type type) {
    19       return type.GetInterface(typeof(IDictionary).FullName) != null;
     20      return ReflectionTools.HasDefaultConstructor(type) &&
     21        type.GetInterface(typeof(IDictionary).FullName) != null;
    2022    }
    2123
     
    5456      } catch (ArgumentException e) {
    5557        throw new PersistenceException("Duplicate dictionary key.", e);
    56       }     
     58      }
    5759    }
    5860  }
  • trunk/sources/HeuristicLab.Persistence/3.3/Default/Decomposers/EnumerableDecomposer.cs

    r1683 r1705  
    66using System.Collections.Generic;
    77using HeuristicLab.Persistence.Default.Decomposers.Storable;
     8using HeuristicLab.Persistence.Auxiliary;
    89
    910namespace HeuristicLab.Persistence.Default.Decomposers {
     
    1920    public bool CanDecompose(Type type) {
    2021      return
     22        ReflectionTools.HasDefaultConstructor(type) &&
    2123        type.GetInterface(typeof(IEnumerable).FullName) != null &&
    2224        type.GetMethod("Add") != null &&
  • trunk/sources/HeuristicLab.Persistence/3.3/Default/Decomposers/NumberEnumerable2StringDecomposer.cs

    r1644 r1705  
    77using System.Text;
    88using HeuristicLab.Persistence.Default.Decomposers.Storable;
     9using HeuristicLab.Persistence.Auxiliary;
    910
    1011namespace HeuristicLab.Persistence.Default.Decomposers {
     
    5455    public bool CanDecompose(Type type) {
    5556      return
     57        ReflectionTools.HasDefaultConstructor(type) &&
    5658        ImplementsGenericEnumerable(type) &&
    5759        HasAddMethod(type);
  • trunk/sources/HeuristicLab.Persistence/3.3/Default/Decomposers/Storable/StorableDecomposer.cs

    r1679 r1705  
    44using HeuristicLab.Persistence.Interfaces;
    55using HeuristicLab.Persistence.Core;
     6using System.Reflection;
     7using HeuristicLab.Persistence.Auxiliary;
    68
    79namespace HeuristicLab.Persistence.Default.Decomposers.Storable {
     
    1517
    1618    public bool CanDecompose(Type type) {
    17       return StorableAttribute.GetStorableMembers(type, false).Count() > 0 ||
    18         EmptyStorableClassAttribute.IsEmptyStorable(type);
     19      return ReflectionTools.HasDefaultConstructor(type) &&
     20        (StorableAttribute.GetStorableMembers(type, false).Count() > 0 ||
     21          EmptyStorableClassAttribute.IsEmptyStorable(type));
    1922
    2023    }
     
    2629    public IEnumerable<Tag> Decompose(object obj) {
    2730      foreach (var mapping in StorableAttribute.GetStorableAccessors(obj)) {
    28         yield return new Tag(mapping.Value.Name ?? mapping.Key, mapping.Value.Get());       
     31        yield return new Tag(mapping.Value.Name ?? mapping.Key, mapping.Value.Get());
    2932      }
    3033    }
Note: See TracChangeset for help on using the changeset viewer.