Exemple #1
0
        internal static async Task BindAsyncCollectorAsync <T>(Stream stream, IBinderEx binder, RuntimeBindingContext runtimeContext)
        {
            IAsyncCollector <T> collector = await binder.BindAsync <IAsyncCollector <T> >(runtimeContext);

            // first read the input stream as a collection
            ICollection <JToken> values = ReadAsCollection(stream);

            // convert values as necessary and add to the collector
            foreach (var value in values)
            {
                object converted = null;
                if (typeof(T) == typeof(string))
                {
                    converted = value.ToString();
                }
                else if (typeof(T) == typeof(JObject))
                {
                    converted = (JObject)value;
                }
                else
                {
                    throw new ArgumentException("Unsupported collection type.");
                }

                await collector.AddAsync((T)converted);
            }
        }
Exemple #2
0
        internal static async Task BindStreamAsync(Stream stream, FileAccess access, IBinderEx binder, RuntimeBindingContext runtimeContext)
        {
            Stream boundStream = await binder.BindAsync <Stream>(runtimeContext);

            if (access == FileAccess.Write)
            {
                await stream.CopyToAsync(boundStream);
            }
            else
            {
                await boundStream.CopyToAsync(stream);
            }
        }