コード例 #1
0
        public Task <IImageSourceServiceResult <UIImage> > GetImageAsync(ICustomImageSourceStub imageSource, float scale = 1, CancellationToken cancellationToken = default)
        {
            var color = imageSource.Color;

            var drawable = _cache.Get(color);

            var result = new ImageSourceServiceResult(drawable, () => _cache.Return(color));

            return(Task.FromResult <IImageSourceServiceResult <UIImage> >(result));
        }
コード例 #2
0
            public override Task <IImageSourceServiceResult <Drawable> > GetDrawableAsync(IImageSource imageSource, Context context, CancellationToken cancellationToken = default)
            {
                if (imageSource is not ICustomImageSourceStub imageSourceStub)
                {
                    return(Task.FromResult <IImageSourceServiceResult <Drawable> >(null));
                }

                var color = imageSourceStub.Color;

                var drawable = _cache.Get(color);

                var result = new ImageSourceServiceResult(drawable, () => _cache.Return(color));

                return(Task.FromResult <IImageSourceServiceResult <Drawable> >(result));
            }
コード例 #3
0
        public void ResultsDisposeCorrectlyAndOnce()
        {
            var dispose = 0;

            var cache = new CustomImageCacheStub();
            var image = cache.Get(Colors.Red);

            var result = new ImageSourceServiceResult(image, () => dispose++);

            Assert.False(result.IsDisposed);
            Assert.Equal(0, dispose);

            result.Dispose();

            Assert.True(result.IsDisposed);
            Assert.Equal(1, dispose);

            result.Dispose();

            Assert.True(result.IsDisposed);
            Assert.Equal(1, dispose);

            cache.Return(Colors.Red);
        }
コード例 #4
0
        public async Task ResultsDisposeCorrectlyAndOnce()
        {
            var dispose = 0;

            var cache = new CustomImageCacheStub();
            var image = await InvokeOnMainThreadAsync(() => cache.Get(Colors.Red));

            var result = new ImageSourceServiceResult(image, () => dispose++);

            Assert.False(result.IsDisposed);
            Assert.Equal(0, dispose);

            result.Dispose();

            Assert.True(result.IsDisposed);
            Assert.Equal(1, dispose);

            result.Dispose();

            Assert.True(result.IsDisposed);
            Assert.Equal(1, dispose);

            cache.Return(Colors.Red);
        }