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 SiliconStudio.Core.Reflection;
5 using SiliconStudio.Core.Serialization;
6 
7 namespace SiliconStudio.Paradox.Effects
8 {
9  public class ParameterKeySerializer<T> : DataSerializer<ParameterKey<T>>
10  {
11  public override void Serialize(ref ParameterKey<T> obj, ArchiveMode mode, SerializationStream stream)
12  {
13  if (mode == ArchiveMode.Serialize)
14  {
15  stream.Write(obj.Name);
16  stream.Write(obj.Length);
17  }
18  else
19  {
20  var parameterName = stream.ReadString();
21  var parameterLength = stream.ReadInt32();
22  obj = (ParameterKey<T>)ParameterKeys.FindByName(parameterName);
23 
24  // If parameter could not be found, create one matching this type.
25  if (obj == null)
26  {
28  obj = new ParameterKey<T>(parameterName, parameterLength, metadata);
29  ParameterKeys.Merge(obj, null, parameterName);
30  }
31  }
32  }
33  }
34 }
Key of an gereric effect parameter.
_In_ size_t _In_ const TexMetadata & metadata
Definition: DirectXTexP.h:116
Base class for implementation of SerializationStream.
static ParameterKey FindByName(string name)
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 ParameterKey< T > obj, ArchiveMode mode, SerializationStream stream)