Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
DataConverter.Generics.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  /// Typed Converter class to/from a given data type.
9  /// </summary>
10  /// <typeparam name="TData">The type of the data.</typeparam>
11  /// <typeparam name="T">The type of the source.</typeparam>
12  public abstract class DataConverter<TData, T> : DataConverter
13  {
14  /// <inheritdoc/>
15  public override Type DataType
16  {
17  get { return typeof(TData); }
18  }
19 
20  /// <inheritdoc/>
21  public override Type ObjectType
22  {
23  get { return typeof(T); }
24  }
25 
26 
27  public virtual void ConstructFromData(ConverterContext converterContext, TData data, ref T obj)
28  {
29  }
30 
31  /// <inheritdoc/>
32  public override void ConstructFromData(ConverterContext converterContext, object data, ref object obj)
33  {
34  var dataT = (TData)data;
35  var objT = (T)obj;
36  ConstructFromData(converterContext, dataT, ref objT);
37  obj = objT;
38  }
39 
40 
41  public abstract void ConvertFromData(ConverterContext converterContext, TData data, ref T obj);
42 
43  /// <inheritdoc/>
44  public override void ConvertFromData(ConverterContext converterContext, object data, ref object obj)
45  {
46  var dataT = (TData)data;
47  var objT = (T)obj;
48  ConvertFromData(converterContext, dataT, ref objT);
49  obj = objT;
50  }
51 
52  /// <summary>
53  /// Converts the given source object to its data counterpart.
54  /// </summary>
55  /// <param name="converterContext">The converter context.</param>
56  /// <param name="data">The data.</param>
57  /// <param name="obj"></param>
58  public abstract void ConvertToData(ConverterContext converterContext, ref TData data, T obj);
59 
60  /// <inheritdoc/>
61  public override void ConvertToData(ConverterContext converterContext, ref object data, object obj)
62  {
63  var dataT = (TData)data;
64  var objT = (T)obj;
65  ConvertToData(converterContext, ref dataT, objT);
66  data = dataT;
67  }
68  }
69 }
virtual void ConstructFromData(ConverterContext converterContext, TData data, ref T obj)
Base class for converters to/from a data type.
override void ConvertFromData(ConverterContext converterContext, object data, ref object obj)
Converts the given data to its object counterpart. The converter context.The data.The object.
override void ConvertToData(ConverterContext converterContext, ref object data, object obj)
Converts the given source object to its data counterpart. The converter context.The data...
override void ConstructFromData(ConverterContext converterContext, object data, ref object obj)