private void WritePropertyValues(DataBuffer buff, object inst) { object[] values = new object[Properties.Length]; Type[] types = new Type[values.Length]; bool[] isNull = new bool[values.Length]; for (int i = 0; i < values.Length; i++) { values[i] = Properties[i].GetValue(inst); types[i] = Properties[i].PropertyType; isNull[i] = values[i] == null; } var fold = DataHelpers.Fold(isNull); for (int i = 0; i < fold.Length; i++) { buff.Write((byte)fold[i]); } for (int i = 0; i < values.Length; i++) { if (values[i] != null) { Parent.Write(buff, types[i], values[i]); } } }
private void WriteEnum(DataBuffer buffer, object data) { var underlying = data.GetType().GetEnumUnderlyingType(); byte underlyingValue = (byte)((IConvertible)data).ToType(typeof(byte), null); buffer.Write((byte)underlyingValue); }
private void WriteEnumerable(DataBuffer buffer, object inst) { IEnumerable <object> list = (inst as IEnumerable).OfType <object>(); short count = (short)list.Count(); buffer.Write((short)count); foreach (var obj in list) { if (obj.GetType() != ListType) { throw new Exception("Type mismatch"); } Parent.Write(buffer, ListType, obj); } }
public void WriteTo(DataBuffer buffer) { var bytes = ToBytes(); buffer.Write((byte[])bytes); }
public void WriteTo(DataBuffer buffer) { buffer.Write((short)UserId); }