public void SerializeToStream(object source, string identifier, BinaryWriter writer) { SBinaryBlockEntry block = new SBinaryBlockEntry(); block.Identifier = identifier; writer.Write(Encoding.UTF8.GetBytes(identifier)); Type type = source.GetType(); // Check object serializable attribute if (type.IsPrimitive) { dynamic value = source as Type; writer.Write(value); return; } string previousIdentifier = identifier; foreach (PropertyInfo propertyInfo in type.GetProperties(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public)) { Type propertyType = propertyInfo.PropertyType; if (propertyType.IsPrimitive) { } } }
private void AddDataBlocks(object source, string identifier, List <SBinaryBlockEntry> blocks) { SBinaryBlockEntry newBlock = new SBinaryBlockEntry(); newBlock.Identifier = identifier; // Use BitConverter for primitive types Type sourceType = source.GetType(); if (sourceType.IsPrimitive) { dynamic value = source; newBlock.Data = BitConverter.GetBytes(value); blocks.Add(newBlock); return; } if (m_byteConverters.TryGetValue(sourceType, out ConvertToBytes converter)) { newBlock.Data = converter(source); blocks.Add(newBlock); return; } }