public static void WriteToStream(this IEnumerable <IOptionalProperty> properties, BinaryStream stream) { var p = properties ?? new IOptionalProperty[0]; stream.AppendInt(p.Count()); foreach (var property in p) { stream.AppendByte((byte)property.Type); stream.AppendObject(property.Value); } }