3using System.Collections.Generic;
14 private readonly Dictionary<int, string> keywordsDictionary;
21 keywordsDictionary =
new Dictionary<int, string>();
30 public List<SerializationInfo>
Read(Stream serializationStream)
32 var returnValue =
new List<SerializationInfo>();
33 int childCount, valueCount, referenceId;
34 string systemName, enumTypeName;
37 this.keywordsDictionary.Clear();
39 using (var reader =
new BinaryReader(serializationStream))
41 var totalCount = reader.ReadInt32();
42 for (var counter = 0; counter < totalCount; counter++)
46 ReferenceId = reader.ReadInt32(),
47 TypeName = ReadString(reader)
50 childCount = reader.ReadInt32();
51 for (var childCounter = 0; childCounter < childCount; childCounter++)
53 systemName = ReadString(reader);
54 isDirty = reader.ReadBoolean();
55 referenceId = reader.ReadInt32();
56 info.AddChild(systemName, referenceId, isDirty);
59 valueCount = reader.ReadInt32();
60 for (var valueCounter = 0; valueCounter < valueCount; valueCounter++)
62 systemName = ReadString(reader);
63 enumTypeName = ReadString(reader);
64 isDirty = reader.ReadBoolean();
65 value = ReadObject(reader);
66 info.AddValue(systemName, value, isDirty,
string.IsNullOrEmpty(enumTypeName) ?
null : enumTypeName);
68 returnValue.Add(info);
75 private string ReadString(BinaryReader reader) =>
78 private string ReadString(BinaryReader reader,
CslaKnownTypes knownType)
83 return reader.ReadString();
85 var systemString = reader.ReadString();
86 this.keywordsDictionary.Add(reader.ReadInt32(), systemString);
89 return this.keywordsDictionary[reader.ReadInt32()];
95 private object ReadObject(BinaryReader reader)
101 using (MemoryStream arrayBuffer =
new MemoryStream(reader.ReadBytes(reader.ReadInt32())))
103 var formatter = SerializationFormatterFactory.GetFormatter();
104 var obj = formatter.Deserialize(arrayBuffer);
108 return reader.ReadBoolean();
110 return reader.ReadChar();
112 return reader.ReadSByte();
114 return reader.ReadByte();
116 return reader.ReadInt16();
118 return reader.ReadUInt16();
120 return reader.ReadInt32();
122 return reader.ReadUInt32();
124 return reader.ReadInt64();
126 return reader.ReadUInt64();
128 return reader.ReadSingle();
130 return reader.ReadDouble();
132 var decimalBits =
new int[4];
133 for (var counter = 0; counter < 4; counter++)
135 decimalBits[counter] = reader.ReadInt32();
137 return new decimal(decimalBits);
139 return new DateTime(reader.ReadInt64());
141 return new TimeSpan(reader.ReadInt64());
145 return new Guid(reader.ReadBytes(16));
147 return reader.ReadBytes(reader.ReadInt32());
149 var count = reader.ReadInt32();
150 var result =
new byte[count][];
151 for (
int i = 0; i < count; i++)
152 result[i] = reader.ReadBytes(reader.ReadInt32());
155 return reader.ReadChars(reader.ReadInt32());
157 var total = reader.ReadInt32();
158 var buffer =
new int[total];
159 for (var counter = 0; counter < total; counter++)
161 buffer[counter] = reader.ReadInt32();
163 return new List<int>(buffer);
169 return ReadString(reader, knownType);
A strongly-typed resource class, for looking up localized strings, etc.
static string UnandledKNownTypeException
Looks up a localized string similar to Unhandled CSLA Known type was found.
This is a class that is responsible for deserializing SerializationInfo objects for receiving the dat...
CslaBinaryReader()
Creates new instance of CslaBinaryReader
List< SerializationInfo > Read(Stream serializationStream)
Read a data from a stream, typically MemoryStream, and convert it into a list of SerializationInfo ob...
Object containing the serialization data for a specific object.
Represents a reader class that can be used to read the data sent across the wire in byte array format...
CslaKnownTypes
This enumeration contains the list of known types that CslaBinaryReader and CslaBinaryWriterknow abou...
@ DateTimeOffset
Date/time plus time zone / DateTimeOffset
@ TimeSpan
TimeSpan - time span
@ Guid
Globally unique identifier / Guid