Empeld
Empeld plugin documentation.
pluginbase.Objects.Syncable.TypeSerializer Class Reference

Special type serializer that will work with plugins More...

Public Member Functions

string SerializeType (Type type)
 
Type DeserializeType (string fromString)
 

Static Public Member Functions

static string Serialize (Type type)
 
static Type Deserialize (string slug)
 

Properties

static TypeSerializer Instance [get]
 

Detailed Description

Special type serializer that will work with plugins

Member Function Documentation

◆ Deserialize()

static Type pluginbase.Objects.Syncable.TypeSerializer.Deserialize ( string  slug)
static
138  {
139  return Instance.DeserializeType(slug);
140  }
static TypeSerializer Instance
Definition: TypeSerializer.cs:29
Type DeserializeType(string fromString)
Definition: TypeSerializer.cs:71

◆ DeserializeType()

Type pluginbase.Objects.Syncable.TypeSerializer.DeserializeType ( string  fromString)

Attribute: 0

== '.')

Attribute: fromString

= type;

Attribute: type

= fromString;

72  {
73  if (string.IsNullOrEmpty(fromString) || fromString == NULL_TYPE)
74  {
75  return null;
76  }
77 
78  if (!fromString.StartsWith(PREFIX))
79  {
80  return Type.GetType(fromString);
81  }
82 
83  lock (_lock)
84  {
85  Type type = null;
86  if (!_typeCache.TryGetValue(fromString, out type))
87  {
88  int delimIdx = fromString.IndexOf(',');
89  if (delimIdx > 0)
90  {
91  string asmName = fromString.Substring(PREFIX.Length, delimIdx - PREFIX.Length);
92  string typeName = fromString.Substring(delimIdx + 1);
93 
94  if (typeName.Length > 1 && typeName[0] == '.')
95  {
96  typeName = asmName + typeName;
97  }
98 
99  var asm = FindAssemblyByName(asmName);
100  if (asm != null)
101  {
102  type = asm.GetType(typeName);
103  _typeCache[fromString] = type;
104  _nameCache[type] = fromString;
105  }
106 
107  }
108  }
109 
110  return type;
111  }
112  }

◆ Serialize()

static string pluginbase.Objects.Syncable.TypeSerializer.Serialize ( Type  type)
static
133  {
134  return Instance.SerializeType(type);
135  }
string SerializeType(Type type)
Definition: TypeSerializer.cs:43
static TypeSerializer Instance
Definition: TypeSerializer.cs:29

◆ SerializeType()

string pluginbase.Objects.Syncable.TypeSerializer.SerializeType ( Type  type)

Attribute: type

= slug;

Attribute: slug

= type;

44  {
45  if (type == null)
46  {
47  return NULL_TYPE;
48  }
49 
50  lock (_lock)
51  {
52  string slug;
53  if (!_nameCache.TryGetValue(type, out slug))
54  {
55  string assemblyName = type.Assembly.GetName().Name;
56  string typeName = type.FullName;
57  if (typeName.StartsWith(assemblyName))
58  {
59  typeName = typeName.Substring(assemblyName.Length);
60  }
61  slug = string.Format("{0}{1},{2}", PREFIX, assemblyName, typeName);
62 
63  _nameCache[type] = slug;
64  _typeCache[slug] = type;
65  }
66 
67  return slug;
68  }
69  }

Property Documentation

◆ Instance

TypeSerializer pluginbase.Objects.Syncable.TypeSerializer.Instance
staticget

The documentation for this class was generated from the following file: