public static byte[] SerializeList(object obj) { IList list = obj as IList; if (list == null) { return(new byte[0]); } MemoryStream memoryStream = new MemoryStream(); using (BinaryWriter binaryWriter = new BinaryWriter(memoryStream)) { binaryWriter.Write(list.Count); for (int i = 0; i < list.Count; i++) { byte[] array = BloxSerializer.Serialize(list[i]); binaryWriter.Write(array.Length); binaryWriter.Write(array); } } memoryStream.Flush(); byte[] buffer = memoryStream.GetBuffer(); memoryStream.Close(); return(buffer); }
public static byte[] SerializeArray(object obj) { Array array = obj as Array; if (array == null) { return(new byte[0]); } MemoryStream memoryStream = new MemoryStream(); using (BinaryWriter binaryWriter = new BinaryWriter(memoryStream)) { binaryWriter.Write(array.Length); for (int i = 0; i < array.Length; i++) { byte[] array2 = BloxSerializer.Serialize(array.GetValue(i)); binaryWriter.Write(array2.Length); binaryWriter.Write(array2); } } memoryStream.Flush(); byte[] buffer = memoryStream.GetBuffer(); memoryStream.Close(); return(buffer); }
public BloxBlockData(BloxBlock b) { if (b != null) { Type type = b.GetType(); this.blockSysType = type.AssemblyQualifiedName; this.blockType = b.blockType; this.ident = b.ident; this.active = b.active; this._ed_viewOffs = b._ed_viewOffs; if (b.returnType != null) { this.returnType = b.returnType.AssemblyQualifiedName; this.returnValue = BloxSerializer.Serialize(b.returnValue); } if (b.mi != null && b.mi.IsValid) { this.memberReflectedType = b.mi.ReflectedType.AssemblyQualifiedName; this.memberType = b.mi.MemberType; this.memberName = b.mi.Name; ParameterInfo[] parameters = b.mi.GetParameters(); if (((parameters != null) ? parameters.Length : 0) != 0) { this.paramTypes = new string[parameters.Length]; for (int i = 0; i < parameters.Length; i++) { this.paramTypes[i] = parameters[i].ParameterType.AssemblyQualifiedName; } } } if (type != typeof(BloxBlock)) { FieldInfo[] array = type.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public); this.fields = new BlockField[array.Length]; for (int j = 0; j < array.Length; j++) { object value = array[j].GetValue(b); if (value != null) { this.fields[j].fieldName = array[j].Name; this.fields[j].typeName = array[j].FieldType.AssemblyQualifiedName; this.fields[j].data = BloxSerializer.Serialize(value); } } } } }