Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
PropertyKeySerializer.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 using System.Reflection;
5 
6 namespace SiliconStudio.Core.Serialization.Serializers
7 {
8  public class PropertyKeySerializer<T> : DataSerializer<T> where T : PropertyKey
9  {
10  public override void Serialize(ref T obj, ArchiveMode mode, SerializationStream stream)
11  {
12  if (mode == ArchiveMode.Serialize)
13  {
14  stream.Write(obj.Name);
15  stream.Write(obj.OwnerType.AssemblyQualifiedName);
16  }
17  else
18  {
19  var parameterName = stream.ReadString();
20  var ownerTypeName = stream.ReadString();
21  var ownerType = Type.GetType(ownerTypeName);
22 
23  obj = (T)ownerType.GetTypeInfo().GetDeclaredField(parameterName).GetValue(null);
24  }
25  }
26  }
27 }
Base class for implementation of SerializationStream.
Describes how to serialize and deserialize an object without knowing its type. Used as a common base ...
ArchiveMode
Enumerates the different mode of serialization (either serialization or deserialization).
Definition: ArchiveMode.cs:8
override void Serialize(ref T obj, ArchiveMode mode, SerializationStream stream)
A class that represents a tag propety.
Definition: PropertyKey.cs:17