Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
DataConverter.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 using System;
4 
5 namespace SiliconStudio.Core.Serialization.Converters
6 {
7  /// <summary>
8  /// Base class for converters to/from a data type.
9  /// </summary>
10  public abstract class DataConverter
11  {
12  /// <summary>
13  /// Gets the data type.
14  /// </summary>
15  /// <value>
16  /// The data type.
17  /// </value>
18  public abstract Type DataType { get; }
19 
20  /// <summary>
21  /// Gets the source type.
22  /// </summary>
23  /// <value>
24  /// The source type.
25  /// </value>
26  public abstract Type ObjectType { get; }
27 
28  /// <summary>
29  /// Gets a value indicating whether converted result should be cached in <see cref="ConverterContext"/>.
30  /// </summary>
31  /// <value>
32  /// <c>true</c> if result should be cached; otherwise, <c>false</c>.
33  /// </value>
34  public virtual bool CacheResult
35  {
36  get { return true; }
37  }
38 
39  public virtual bool CanConstruct
40  {
41  get { return false; }
42  }
43 
44  public virtual void ConstructFromData(ConverterContext converterContext, object data, ref object obj)
45  {
46  }
47 
48  /// <summary>
49  /// Converts the given data to its object counterpart.
50  /// </summary>
51  /// <param name="converterContext">The converter context.</param>
52  /// <param name="data">The data.</param>
53  /// <param name="obj">The object.</param>
54  public abstract void ConvertFromData(ConverterContext converterContext, object data, ref object obj);
55 
56  /// <summary>
57  /// Converts the given source object to its data counterpart.
58  /// </summary>
59  /// <param name="converterContext">The converter context.</param>
60  /// <param name="data">The data.</param>
61  /// <param name="obj">The object.</param>
62  public abstract void ConvertToData(ConverterContext converterContext, ref object data, object obj);
63  }
64 }
Base class for converters to/from a data type.
virtual void ConstructFromData(ConverterContext converterContext, object data, ref object obj)