Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
PropertyInfoSerializer.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 PropertyInfoSerializer : DataSerializer<PropertyInfo>
9  {
10  public override void Serialize(ref PropertyInfo propertyInfo, ArchiveMode mode, SerializationStream stream)
11  {
12  if (mode == ArchiveMode.Serialize)
13  {
14  stream.Write(propertyInfo.DeclaringType.AssemblyQualifiedName);
15  stream.Write(propertyInfo.Name);
16  }
17  else
18  {
19  var declaringTypeName = stream.ReadString();
20  var propertyName = stream.ReadString();
21 
22  var ownerType = Type.GetType(declaringTypeName);
23  if (ownerType == null)
24  throw new InvalidOperationException("Could not find the appropriate type.");
25 
26  propertyInfo = ownerType.GetTypeInfo().GetDeclaredProperty(propertyName);
27  }
28  }
29  }
30 }
override void Serialize(ref PropertyInfo propertyInfo, ArchiveMode mode, SerializationStream stream)
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