예제 #1
0
    protected override async Task PrimitiveCollectionSerializeOverrideAsync(BoundedStream stream, object boundValue, ValueValueNode childSerializer,
                                                                            SerializedType childSerializedType, FieldLength itemLength, long?itemCount, CancellationToken cancellationToken)
    {
        var list = (IList)boundValue;

        // Handle const-sized mismatched collections
        PadList(ref list, itemCount);

        foreach (var value in list)
        {
            if (stream.IsAtLimit)
            {
                break;
            }

            await childSerializer.SerializeAsync(stream, value, childSerializedType, itemLength, cancellationToken)
            .ConfigureAwait(false);
        }
    }
예제 #2
0
    protected override async Task PrimitiveCollectionSerializeOverrideAsync(BoundedStream stream, object boundValue, ValueValueNode childSerializer,
                                                                            SerializedType childSerializedType, FieldLength itemLength, long?itemCount, CancellationToken cancellationToken)
    {
        var array = (Array)BoundValue;

        // Handle const-sized mismatched collections
        PadArray(ref array, itemCount);

        for (var i = 0; i < array.Length; i++)
        {
            if (stream.IsAtLimit)
            {
                break;
            }

            var value = array.GetValue(i);
            await childSerializer.SerializeAsync(stream, value, childSerializedType, itemLength, cancellationToken)
            .ConfigureAwait(false);
        }
    }