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
RevLine 
[1357]1using System;
2using System.Collections;
[1419]3using System.Collections.Generic;
[1434]4using HeuristicLab.Persistence.Core;
[1357]5
6namespace HeuristicLab.Persistence.Interfaces {
7
[1434]8  public class Tag {
[1437]9    public List<Thunk> finalFixes;
[1434]10    public string Name { get; private set; }
11    public object Value;     
12
[1419]13    public Tag(string name, object value) {
[1434]14      this.Name = name;
15      this.Value = value;
[1419]16    }
17    public Tag(object value) {
[1434]18      this.Name = null;
19      this.Value = value;
[1419]20    }
[1435]21    public void SafeSet(Setter setter) {
[1434]22      if ( Value != null && Value.GetType() == typeof(ParentReference))
23        finalFixes.Add(() => setter(Value));
24      else
25        setter(Value);
26    }
[1419]27  }
28
[1357]29  public interface IDecomposer {
[1419]30
31    /// <summary>
32    /// Determines for every type whether the decomposer is applicable.
33    /// </summary>   
[1360]34    bool CanDecompose(Type type);
[1357]35
[1419]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
[1357]59}
Note: See TracBrowser for help on using the repository browser.