Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
ContentReferenceDataSerializer.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.Serialization.Contents;
5 
6 namespace SiliconStudio.Core.Serialization
7 {
8  public sealed class ContentReferenceDataSerializer<T> : DataSerializer<ContentReference<T>> where T : class
9  {
10  public override void Serialize(ref ContentReference<T> contentReference, ArchiveMode mode, SerializationStream stream)
11  {
12  var contentSerializerContext = stream.Context.Get(ContentSerializerContext.ContentSerializerContextProperty);
13  if (contentSerializerContext != null)
14  {
15  if (mode == ArchiveMode.Serialize)
16  {
17  int index = contentSerializerContext.AddContentReference(contentReference);
18  stream.Write(index);
19  }
20  else
21  {
22  int index = stream.ReadInt32();
23  contentReference = contentSerializerContext.GetContentReference<T>(index);
24  }
25  }
26  else
27  {
28  // This case will happen when serializing build engine command hashes: we still want Location to still be written
29  if (mode == ArchiveMode.Serialize)
30  {
31  {
32  // This case will happen when serializing build engine command hashes: we still want Location to still be written
33  stream.Write(contentReference.Location);
34  }
35  }
36  else
37  {
38  // No real case yet
39  throw new NotSupportedException();
40  }
41  }
42  }
43  }
44 }
override void Serialize(ref ContentReference< T > contentReference, 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