Free cookie consent management tool by TermsFeed Policy Generator

source: branches/New Persistence Exploration/Persistence/Persistence/Interfaces/IDecomposer.cs @ 1437

Last change on this file since 1437 was 1437, checked in by epitzer, 15 years ago

Cleanup DeSerializer code. (#506)

File size: 1.8 KB
Line 
1using System;
2using System.Collections;
3using System.Collections.Generic;
4using HeuristicLab.Persistence.Core;
5
6namespace HeuristicLab.Persistence.Interfaces {
7
8  public class Tag {
9    public List<Thunk> finalFixes;
10    public string Name { get; private set; }
11    public object Value;     
12
13    public Tag(string name, object value) {
14      this.Name = name;
15      this.Value = value;
16    }
17    public Tag(object value) {
18      this.Name = null;
19      this.Value = value;
20    }
21    public void SafeSet(Setter setter) {
22      if ( Value != null && Value.GetType() == typeof(ParentReference))
23        finalFixes.Add(() => setter(Value));
24      else
25        setter(Value);
26    }
27  }
28
29  public interface IDecomposer {
30
31    /// <summary>
32    /// Determines for every type whether the decomposer is applicable.
33    /// </summary>   
34    bool CanDecompose(Type type);
35
36    /// <summary>
37    /// Decompose an object into KeyValuePairs, the Key can be null,
38    /// the order in which elements are generated is guaranteed to be
39    /// the same as they are supplied in the Compose method.
40    /// </summary>   
41    IEnumerable<Tag> DeCompose(object obj);
42
43    /// <summary>
44    /// Create an instance of the object if possible. May return null
45    /// in which case the Populate method must create the instance.
46    /// </summary>
47    /// <param name="type"></param>
48    /// <returns></returns>
49    object CreateInstance(Type type);
50
51    /// <summary>
52    /// Compose an object from the KeyValuePairs previously generated
53    /// in DeCompose. The order in which the values are supplied is
54    /// the same as they where generated. Keys might be null.
55    /// </summary>   
56    object Populate(object instance, IEnumerable<Tag> tags, Type type);
57  } 
58
59}
Note: See TracBrowser for help on using the repository browser.