Tanoda
pb_SerializableObject.cs
Go to the documentation of this file.
1using System;
2using UnityEngine;
3using System.Linq;
4using System.Reflection;
5using System.Collections;
6using System.Collections.Generic;
7using System.Runtime.Serialization;
8using GILES;
9
10namespace GILES.Serialization
11{
16 [System.Serializable]
18 {
20 protected T target;
21
22 public Type type { get; set; }
23
25 protected Dictionary<string, object> reflectedProperties;
26
31 {
32 this.target = obj;
33 }
34
39 public static explicit operator T(pb_SerializableObject<T> obj)
40 {
41 if(obj.target == null)
42 {
43 T val = default(T);
44 obj.ApplyProperties(val);
45 return val;
46 }
47 else
48 {
49 return obj.target;
50 }
51 }
52
53 public object GetObject(string key)
54 {
55 if (reflectedProperties.ContainsKey(key))
56 {
57 return reflectedProperties[key];
58 }
59 else
60 {
61 return null;
62 }
63 }
64
68 public pb_SerializableObject(SerializationInfo info, StreamingContext context)
69 {
70 string typeName = (string) info.GetValue("typeName", typeof(string));
71 type = Type.GetType(typeName);
72 reflectedProperties = (Dictionary<string, object>) info.GetValue("reflectedProperties", typeof(Dictionary<string, object>));
73 }
74
78 public void GetObjectData(SerializationInfo info, StreamingContext context)
79 {
80 Type type = target.GetType();
81 info.AddValue("typeName", type.AssemblyQualifiedName, typeof(string));
82
84 info.AddValue("reflectedProperties", reflectedProperties, typeof(Dictionary<string, object>));
85 }
86
87 public virtual void ApplyProperties(object obj)
88 {
90
91 if(ser != null)
92 {
94 }
95 else
96 {
97 pb_Reflection.ApplyProperties(obj, reflectedProperties);
98 }
99 }
100
101 public virtual Dictionary<string, object> PopulateSerializableDictionary()
102 {
104
105 if(ser != null)
107 else
108 return pb_Reflection.ReflectProperties(target);
109 }
110 }
111}
virtual Dictionary< string, object > PopulateSerializableDictionary()
T target
A reference to the component being serialized. Will be null on deserialization.
virtual void ApplyProperties(object obj)
Called after an object is deserialized and constructed to it's base type.
void GetObjectData(SerializationInfo info, StreamingContext context)
Type type
The type of component stored.
pb_SerializableObject(SerializationInfo info, StreamingContext context)
Dictionary< string, object > reflectedProperties
A key-value store of all serializable properties and fields on this object. Populated on serializatio...
Dictionary< string, object > PopulateSerializableDictionary()
void ApplyDictionaryValues(Dictionary< string, object > values)