CSLA.NET 5.4.2
CSLA .NET is a software development framework that helps you build a reusable, maintainable object-oriented business layer for your app.
CslaLegacyBinaryReader.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using System.IO;
4using Csla.Properties;
5
7{
13 {
14 private readonly Dictionary<int, string> keywordsDictionary;
15
20 {
21 keywordsDictionary = new Dictionary<int, string>();
22 }
23
30 public List<SerializationInfo> Read(Stream serializationStream)
31 {
32 var returnValue = new List<SerializationInfo>();
33 int childCount, valueCount, referenceId;
34 string systemName, enumTypeName;
35 bool isDirty;
36 object value;
37 keywordsDictionary.Clear();
38 using (var reader = new BinaryReader(serializationStream))
39 {
40 var totalCount = reader.ReadInt32();
41 for (var counter = 0; counter < totalCount; counter++)
42 {
43 var info = new SerializationInfo();
44 info.ReferenceId = reader.ReadInt32();
45 info.TypeName = (string)ReadObject(reader);
46
47 childCount = reader.ReadInt32();
48 for (var childCounter = 0; childCounter < childCount; childCounter++)
49 {
50 systemName = (string)ReadObject(reader);
51 isDirty = (bool)ReadObject(reader);
52 referenceId = (int)ReadObject(reader);
53 info.AddChild(systemName, referenceId, isDirty);
54 }
55
56 valueCount = reader.ReadInt32();
57 for (var valueCounter = 0; valueCounter < valueCount; valueCounter++)
58 {
59 systemName = (string)ReadObject(reader);
60 enumTypeName = (string)ReadObject(reader);
61 isDirty = (bool)ReadObject(reader);
62 value = ReadObject(reader);
63 info.AddValue(systemName, value, isDirty, string.IsNullOrEmpty(enumTypeName) ? null : enumTypeName);
64 }
65 returnValue.Add(info);
66 }
67 }
68
69 return returnValue;
70 }
71
72 private object ReadObject(BinaryReader reader)
73 {
74 var knownType = (CslaKnownTypes)reader.ReadByte();
75 switch (knownType)
76 {
77 case CslaKnownTypes.Boolean:
78 return reader.ReadBoolean();
79 case CslaKnownTypes.Char:
80 return reader.ReadChar();
81 case CslaKnownTypes.SByte:
82 return reader.ReadSByte();
83 case CslaKnownTypes.Byte:
84 return reader.ReadByte();
85 case CslaKnownTypes.Int16:
86 return reader.ReadInt16();
87 case CslaKnownTypes.UInt16:
88 return reader.ReadUInt16();
89 case CslaKnownTypes.Int32:
90 return reader.ReadInt32();
91 case CslaKnownTypes.UInt32:
92 return reader.ReadUInt32();
93 case CslaKnownTypes.Int64:
94 return reader.ReadInt64();
95 case CslaKnownTypes.UInt64:
96 return reader.ReadUInt64();
97 case CslaKnownTypes.Single:
98 return reader.ReadSingle();
99 case CslaKnownTypes.Double:
100 return reader.ReadDouble();
101 case CslaKnownTypes.Decimal:
102 var totalBits = reader.ReadInt32();
103 var decimalBits = new int[totalBits];
104 for (var counter = 0; counter < totalBits; counter++)
105 {
106 decimalBits[counter] = reader.ReadInt32();
107 }
108 return new Decimal(decimalBits);
109 case CslaKnownTypes.DateTime:
110 return new DateTime(reader.ReadInt64());
111 case CslaKnownTypes.String:
112 return reader.ReadString();
113 case CslaKnownTypes.TimeSpan:
114 return new TimeSpan(reader.ReadInt64());
115 case CslaKnownTypes.DateTimeOffset:
116 return new DateTimeOffset(reader.ReadInt64(), new TimeSpan(reader.ReadInt64()));
117 case CslaKnownTypes.Guid:
118 return new Guid(reader.ReadBytes(16)); // 16 bytes in a Guid
119 case CslaKnownTypes.ByteArray:
120 return reader.ReadBytes(reader.ReadInt32());
121 case CslaKnownTypes.ByteArrayArray:
122 var count = reader.ReadInt32();
123 var result = new byte[count][];
124 for (int i = 0; i < count; i++)
125 result[i] = reader.ReadBytes(reader.ReadInt32());
126 return result;
127 case CslaKnownTypes.CharArray:
128 return reader.ReadChars(reader.ReadInt32());
129 case CslaKnownTypes.ListOfInt:
130 var returnValue = new List<int>();
131 var total = reader.ReadInt32();
132 for (var counter = 0; counter < total; counter++)
133 {
134 returnValue.Add(reader.ReadInt32());
135 }
136 return returnValue;
137 case CslaKnownTypes.Null:
138 return null;
139 case CslaKnownTypes.StringWithDictionaryKey:
140 var systemString = reader.ReadString();
141 keywordsDictionary.Add(reader.ReadInt32(), systemString);
142 return systemString;
143 case CslaKnownTypes.StringDictionaryKey:
144 return keywordsDictionary[reader.ReadInt32()];
145 default:
146 throw new ArgumentOutOfRangeException(Resources.UnandledKNownTypeException);
147 }
148 }
149
150 }
151}
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 legacy version of CslaBinaryReader.
CslaLegacyBinaryReader()
Creates new instance of CslaLegacyBinaryReader
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...
Definition: ICslaReader.cs:12
CslaKnownTypes
This enumeration contains the list of known types that CslaBinaryReader and CslaBinaryWriterknow abou...