Empeld
Empeld plugin documentation.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Pages
pluginbase.Helpers.BinaryCodecs Namespace Reference

Namespaces

namespace  Providers
 

Classes

class  BinaryCodecAttribute
 Attribute that tells us how to encode a specific class More...
 
class  Codecs
 
class  CodecSet
 
interface  IBinaryCodec
 Defines an interface to get a codec for a type More...
 
struct  TypeCodec
 Defines how to encode and decode a type More...
 

Functions

 CodecSet ()
 
 CodecSet (IEnumerable< IBinaryCodec > codecs)
 
void Add (IBinaryCodec codec)
 
void Add (IEnumerable< IBinaryCodec > codecs)
 
TypeCodec GetCodec (Type type)
 
TypeCodec GetCodec< T > ()
 
CodecSet Clone ()
 

Function Documentation

◆ Add() [1/2]

void pluginbase.Helpers.BinaryCodecs.Add ( IBinaryCodec  codec)
28  {
29  _codecs.Insert(0, codec);
30  }

◆ Add() [2/2]

void pluginbase.Helpers.BinaryCodecs.Add ( IEnumerable< IBinaryCodec codecs)
33  {
34  foreach(var codec in codecs)
35  {
36  this.Add(codec);
37  }
38  }
void Add(IEnumerable< IBinaryCodec > codecs)
Definition: CodecSet.cs:32

◆ Clone()

object ICloneable pluginbase.Helpers.BinaryCodecs.Clone ( )
67  {
68  return new CodecSet(_codecs);
69  }
CodecSet(IEnumerable< IBinaryCodec > codecs)
Definition: CodecSet.cs:22

◆ CodecSet() [1/2]

19  :this(_globalCodecs)
20  { }

◆ CodecSet() [2/2]

23  {
24  _codecs = new List<IBinaryCodec>(codecs);
25  }

◆ GetCodec()

TypeCodec pluginbase.Helpers.BinaryCodecs.GetCodec ( Type  type)

Attribute: i

.GetCodec(type);

41  {
42  //Search anything defined on the class
43  var attr = type.GetCustomAttributes(typeof(BinaryCodecAttribute), true).SingleOrDefault() as BinaryCodecAttribute;
44  if (attr != null)
45  {
46  var codec = attr.Codec.GetCodec(type);
47  if (codec.HasValue)
48  return codec;
49  }
50 
51  //Search global codecs
52  for (int i=0; i<_codecs.Count; ++i)
53  {
54  var codec = _codecs[i].GetCodec(type);
55  if (codec.HasValue)
56  return codec;
57  }
58  return null;
59  }

◆ GetCodec< T >()

62  {
63  return GetCodec(typeof(T));
64  }
TypeCodec GetCodec(Type type)
Definition: CodecSet.cs:40