Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
ParameterKeySerializer.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.Assets;
7 using SiliconStudio.Assets.Serializers;
8 using SiliconStudio.Core.Yaml;
9 using SiliconStudio.Paradox.Effects;
10 
11 namespace SiliconStudio.Paradox.Assets.Serializers
12 {
13  /// <summary>
14  /// A Yaml serializer for <see cref="ParameterKey"/>
15  /// </summary>
16  [YamlSerializerFactory]
17  internal class ParameterKeySerializer : AssetScalarSerializerBase
18  {
19  public override bool CanVisit(Type type)
20  {
21  return typeof(ParameterKey).IsAssignableFrom(type);
22  }
23 
24  public override object ConvertFrom(ref ObjectContext objectContext, Scalar fromScalar)
25  {
26  var parameterKey = ParameterKeys.FindByName(fromScalar.Value);
27  if (parameterKey == null)
28  {
29  parameterKey = ParameterKeys.New<object>(null, fromScalar.Value);
30  // Dont' throw an exception if keys was not found
31  //throw new YamlException(fromScalar.Start, fromScalar.End, "Unable to find registered ParameterKey [{0}]".ToFormat(fromScalar.Value));
32  }
33  return parameterKey;
34  }
35 
36  protected override void WriteScalar(ref ObjectContext objectContext, ScalarEventInfo scalar)
37  {
38  // TODO: if ParameterKey is written to an object, It will not serialized a tag
39  scalar.Tag = null;
40  scalar.IsPlainImplicit = true;
41  base.WriteScalar(ref objectContext, scalar);
42  }
43 
44  public override string ConvertTo(ref ObjectContext objectContext)
45  {
46  return ((ParameterKey)objectContext.Instance).Name;
47  }
48  }
49 }
Key of an effect parameter.
Definition: ParameterKey.cs:15