protected override void WriteBody(object obj, TLSerializationContext context) { for (int i = 0; i < _serializationAgents.Length; i++) { ITLPropertySerializationAgent agent = _serializationAgents[i]; agent.Write(obj, context); } }
protected override void WriteBody(object obj, TLSerializationContext context) { bool hasFlags = false; uint flagsValue = 0; hasFlags = CheckForFlags(obj); if (hasFlags) { var properties = obj.GetType().GetProperties(); flagsValue = (uint)properties[0].GetValue(obj); string binary = Convert.ToString(flagsValue, 2); var maxIndex = binary.Length - 1; for (int i = 0; i < _serializationAgents.Length; i++) { var currentPropertyInfo = properties[i]; var propInfo = currentPropertyInfo.GetCustomAttribute <TLPropertyAttribute>(); //convert the flags to binary if (propInfo.IsFlag) { if (maxIndex < propInfo.Flag) { //since the length is smaller than the flag index, it means this flag was not sent in the msg continue; } if (binary[(int)(maxIndex - propInfo.Flag)] == '0') { //if the flag is set to zero continue; } } ITLPropertySerializationAgent agent = _serializationAgents[i]; agent.Write(obj, context); } } else { for (int i = 0; i < _serializationAgents.Length; i++) { ITLPropertySerializationAgent agent = _serializationAgents[i]; agent.Write(obj, context); } } }