Empeld
Empeld plugin documentation.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events
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

static Type pluginbase.Objects.Syncable.TypeSerializer.Deserialize ( string  slug)
static
128  {
129  return Instance.DeserializeType(slug);
130  }
static TypeSerializer Instance
Definition: TypeSerializer.cs:28
Type DeserializeType(string fromString)
Definition: TypeSerializer.cs:67
Type pluginbase.Objects.Syncable.TypeSerializer.DeserializeType ( string  fromString)

Attribute: 0

== '.')

Attribute: fromString

= type;

Attribute: type

= fromString;

68  {
69  if (string.IsNullOrEmpty(fromString) || fromString == NULL_TYPE)
70  {
71  return null;
72  }
73 
74  if (!fromString.StartsWith(PREFIX))
75  {
76  return Type.GetType(fromString);
77  }
78 
79  Type type = null;
80  if (!_typeCache.TryGetValue(fromString, out type))
81  {
82  int delimIdx = fromString.IndexOf(',');
83  if (delimIdx > 0)
84  {
85  string asmName = fromString.Substring(PREFIX.Length, delimIdx - PREFIX.Length);
86  string typeName = fromString.Substring(delimIdx+1);
87 
88  if (typeName.Length > 1 && typeName[0] == '.')
89  {
90  typeName = asmName + typeName;
91  }
92 
93  var asm = FindAssemblyByName(asmName);
94  if (asm != null)
95  {
96  type = asm.GetType(typeName);
97  _typeCache[fromString] = type;
98  _nameCache[type] = fromString;
99  }
100 
101  }
102  }
103 
104  return type;
105  }
static string pluginbase.Objects.Syncable.TypeSerializer.Serialize ( Type  type)
static
123  {
124  return Instance.SerializeType(type);
125  }
string SerializeType(Type type)
Definition: TypeSerializer.cs:42
static TypeSerializer Instance
Definition: TypeSerializer.cs:28
string pluginbase.Objects.Syncable.TypeSerializer.SerializeType ( Type  type)

Attribute: type

= slug;

Attribute: slug

= type;

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

Property Documentation

TypeSerializer pluginbase.Objects.Syncable.TypeSerializer.Instance
staticget

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