Time Rewizer  v.1.1
Created by: Mark Oostveen
MarkOostveen.TimeRewizer.Serialization Class Reference

Utility for serializing and deserializing objects into and from strings More...

+ Collaboration diagram for MarkOostveen.TimeRewizer.Serialization:

Static Public Member Functions

static string SerializeSnapshot (object Object, out Type[] extractedTypes)
 Serializes destructs object and put's it into a string with custom format More...
 
static string SerializeNormal (object Object, out Type[] extractedTypes)
 
static ISnapShot DeserializeSnapshot (string input, Module[] modules)
 Deserialize a string from custom format and then reconstructs corresponding object from string info More...
 
static object DeserializeObject (string input, Module[] modules)
 

Static Package Functions

static Type GetType (ref Module[] modules, string typeName)
 

Detailed Description

Utility for serializing and deserializing objects into and from strings

Member Function Documentation

◆ DeserializeObject()

static object MarkOostveen.TimeRewizer.Serialization.DeserializeObject ( string  input,
Module []  modules 
)
static
72  {
73  return StringToObject(input, modules);
74  }
+ Here is the caller graph for this function:

◆ DeserializeSnapshot()

static ISnapShot MarkOostveen.TimeRewizer.Serialization.DeserializeSnapshot ( string  input,
Module []  modules 
)
static

Deserialize a string from custom format and then reconstructs corresponding object from string info

Parameters
input
modules
Returns
59  {
60  FieldCache cache = JsonUtility.FromJson<FieldCache>(input);
61 
62  ISnapShot newinstance =
63  RewizeUtilityFunctions.CreateInstanceByType(GetType(ref modules,
64  cache.m_Type)) as ISnapShot;
65 
66  newinstance.SetValue(StringToObject(cache.m_Value, modules));
67 
68  return newinstance;
69  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetType()

static Type MarkOostveen.TimeRewizer.Serialization.GetType ( ref Module []  modules,
string  typeName 
)
staticpackage
378  {
379  if (Serialization.m_ResolvedStringTypes.ContainsKey(typeName))
380  {
381  Serialization.m_ResolvedStringTypes.TryGetValue(typeName, out Type dictionaryitem);
382 
383  if (dictionaryitem != null)
384  {
385  return dictionaryitem;
386  }
387  }
388 
389  //find generic type
390  if (typeName.Contains("`"))
391  {
392  return Serialization.GetGenericType(typeName, ref modules);
393  }
394 
395  //need to search all loaded assembly's because you can't find types from other assembly's with type.gettype();
396  for (int i = 0; i < modules.Length; i++)
397  {
398  Type t = modules[i].GetType(typeName);
399  if (t != null)
400  {
401  Serialization.m_ResolvedStringTypes.TryAdd(typeName, t);
402  return t;
403  }
404  }
405 
406  Type value = Serialization.m_ExecutingAssembly.GetType(typeName) ?? Type.GetType(typeName);
407 
408  if (value != null)
409  {
410  Serialization.m_ResolvedStringTypes.TryAdd(typeName, value);
411  }
412 
413  //find type in current assembly
414  return value;
415  }
+ Here is the caller graph for this function:

◆ SerializeNormal()

static string MarkOostveen.TimeRewizer.Serialization.SerializeNormal ( object  Object,
out Type []  extractedTypes 
)
static
45  {
46  string serializedString = "[T]=" + Object.GetType() + ";";
47  serializedString += ObjectToString(Object, out extractedTypes);
48 
49  return serializedString;
50  }
+ Here is the caller graph for this function:

◆ SerializeSnapshot()

static string MarkOostveen.TimeRewizer.Serialization.SerializeSnapshot ( object  Object,
out Type []  extractedTypes 
)
static

Serializes destructs object and put's it into a string with custom format

Parameters
Object
extractedTypes
Returns
32  {
33  string serilizedString = ObjectToString(Object, out extractedTypes);
34 
35  FieldCache cache = new FieldCache()
36  {
37  m_Type = Object.GetType().ToString(),
38  m_Value = serilizedString
39  };
40 
41  return JsonUtility.ToJson(cache);
42  }
+ Here is the caller graph for this function: