Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
ObjectIdSerializer.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 SharpYaml.Events;
5 using SharpYaml.Serialization;
6 using SiliconStudio.Core.Storage;
7 
8 namespace SiliconStudio.Core.Yaml
9 {
10  /// <summary>
11  /// A Yaml serializer for <see cref="ObjectId"/>
12  /// </summary>
13  [YamlSerializerFactory]
14  internal class ObjectIdSerializer : AssetScalarSerializerBase
15  {
16  public override bool CanVisit(Type type)
17  {
18  return type == typeof(ObjectId);
19  }
20 
21  public override object ConvertFrom(ref ObjectContext context, Scalar fromScalar)
22  {
23  ObjectId objectId;
24  ObjectId.TryParse(fromScalar.Value, out objectId);
25  return objectId;
26  }
27 
28  public override string ConvertTo(ref ObjectContext objectContext)
29  {
30  return ((ObjectId)objectContext.Instance).ToString();
31  }
32  }
33 }
A hash to uniquely identify data.
Definition: ObjectId.cs:13