private static int ReadLengthFromStream(Stream stream) { int num = 0; int num2; do { num2 = (int)MessageTraceCollapsedProperty.ReadSingleByteFromStream(stream); num += num2; }while (num2 == 255); return(num); }
private static object ReadPrimitiveValueFromStream(Stream stream, Type typeOfvalue) { if (typeOfvalue == typeof(long)) { return(BitConverter.ToInt64(MessageTraceCollapsedProperty.ReadByteArrayFromStream(stream), 0)); } if (typeOfvalue == typeof(int)) { return(BitConverter.ToInt32(MessageTraceCollapsedProperty.ReadByteArrayFromStream(stream), 0)); } if (typeOfvalue == typeof(Guid)) { return(new Guid(MessageTraceCollapsedProperty.ReadByteArrayFromStream(stream))); } if (typeOfvalue == typeof(string)) { byte b = MessageTraceCollapsedProperty.ReadSingleByteFromStream(stream); switch (b) { case 2: return(Encoding.ASCII.GetString(MessageTraceCollapsedProperty.ReadByteArrayFromStream(stream))); case 3: return(Encoding.Unicode.GetString(MessageTraceCollapsedProperty.ReadByteArrayFromStream(stream))); default: throw new InvalidOperationException(string.Format("Unable to deserialize string from stream. Unknown string serialization algorithm {0}.", b)); } } else { if (typeOfvalue == typeof(DateTime)) { return(DateTime.FromBinary((long)MessageTraceCollapsedProperty.ReadPrimitiveValueFromStream(stream, typeof(long)))); } if (MessageTraceCollapsedProperty.PrimitiveValueFromByteArrayConvertor.ContainsKey(typeOfvalue)) { return(MessageTraceCollapsedProperty.PrimitiveValueFromByteArrayConvertor[typeOfvalue](MessageTraceCollapsedProperty.ReadByteArrayFromStream(stream))); } if (typeOfvalue.IsEnum) { return(Enum.ToObject(typeOfvalue, (int)MessageTraceCollapsedProperty.ReadPrimitiveValueFromStream(stream, typeof(int)))); } return(null); } }