Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
UriYamlSerializer.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.Yaml;
7 
8 namespace SiliconStudio.Assets.Serializers
9 {
10  /// <summary>
11  /// A Yaml serializer for <see cref="PackageVersion"/>
12  /// </summary>
13  [YamlSerializerFactory]
14  internal class UriYamlSerializer : AssetScalarSerializerBase
15  {
16  public override bool CanVisit(Type type)
17  {
18  return typeof(System.Uri) == type;
19  }
20 
21  public override object ConvertFrom(ref ObjectContext context, Scalar fromScalar)
22  {
23  return new System.Uri(fromScalar.Value);
24  }
25 
26  public override string ConvertTo(ref ObjectContext objectContext)
27  {
28  return objectContext.Instance.ToString();
29  }
30  }
31 }