Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
ObjectUrl.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.Storage;
5 using SiliconStudio.Core.Serialization.Serializers;
6 
7 namespace SiliconStudio.Core.Serialization.Assets
8 {
9  [DataContract]
10  [DataSerializer(typeof(ObjectUrl.Serializer))]
11  public struct ObjectUrl : IEquatable<ObjectUrl>
12  {
13  public static readonly ObjectUrl Empty = new ObjectUrl(UrlType.None, string.Empty);
14 
15  public readonly UrlType Type;
16  public readonly string Path;
17 
18  public ObjectUrl(UrlType type, string path)
19  {
20  if (path == null)
21  throw new ArgumentException("path");
22 
23  Type = type;
24  Path = path;
25  }
26 
27  public bool Equals(ObjectUrl other)
28  {
29  return Type == other.Type && string.Equals(Path, other.Path);
30  }
31 
32  public override bool Equals(object obj)
33  {
34  if (ReferenceEquals(null, obj)) return false;
35  return obj is ObjectUrl && Equals((ObjectUrl)obj);
36  }
37 
38  public override int GetHashCode()
39  {
40  unchecked
41  {
42  return ((int)Type * 397) ^ Path.GetHashCode();
43  }
44  }
45 
46  public static bool operator ==(ObjectUrl left, ObjectUrl right)
47  {
48  return left.Equals(right);
49  }
50 
51  public static bool operator !=(ObjectUrl left, ObjectUrl right)
52  {
53  return !left.Equals(right);
54  }
55 
56  public override string ToString()
57  {
58  return Path;
59  }
60 
61  internal class Serializer : DataSerializer<ObjectUrl>
62  {
63  public override void Serialize(ref ObjectUrl obj, ArchiveMode mode, SerializationStream stream)
64  {
65  if (mode == ArchiveMode.Serialize)
66  {
67  stream.Write(obj.Type);
68  stream.Write(obj.Path);
69  }
70  else
71  {
72  var type = stream.Read<UrlType>();
73  var path = stream.ReadString();
74  obj = new ObjectUrl(type, path);
75  }
76  }
77  }
78  }
79 }
Base class for implementation of SerializationStream.
The type of the serialized type will be passed as a generic arguments of the serializer. Example: serializer of A becomes instantiated as Serializer{A}.
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