コード例 #1
0
        protected override Stream AddFileToBackingDirectoryOrDefault(string fileName)
        {
            if (Files.Any(f => f.Name == fileName))
            {
                throw new ArgumentException("A file with the same name already exists.");
            }

            var newFile = new InMemoryVirtualFile(VirtualPathProvider, this)
            {
                FilePath     = VirtualPathProvider.CombineVirtualPath(this.VirtualPath, fileName),
                FileName     = fileName,
                ByteContents = new byte[0],
            };
            var stream = new InMemoryStream((contents) => newFile.ByteContents = contents);

            this.files.Add(newFile);

            return(stream);
        }
コード例 #2
0
        public override Stream OpenWrite(WriteMode mode)
        {
            if (mode == WriteMode.Truncate)
            {
                return(new InMemoryStream((data) =>
                {
                    ByteContents = data;
                }));
            }
            else
            {
                var stream = new InMemoryStream((data) =>
                {
                    ByteContents = data;
                }, ByteContents ?? new byte[0]);

                if (mode == WriteMode.Append)
                {
                    stream.Seek(stream.Length, SeekOrigin.Begin);
                }

                return(stream);
            }
        }
コード例 #3
0
        public override Stream OpenWrite(WriteMode mode)
        {
            if (mode == WriteMode.Truncate)
            {
                return new InMemoryStream((data) =>
                {
                    ByteContents = data;
                });
            }
            else
            {
                var stream = new InMemoryStream((data) =>
                {
                    ByteContents = data;
                }, ByteContents ?? new byte[0]);

                if (mode == WriteMode.Append)
                {
                    stream.Seek(stream.Length, SeekOrigin.Begin);
                }

                return stream;
            }
        }
コード例 #4
0
        protected override Stream AddFileToBackingDirectoryOrDefault(string fileName)
        {
            if (Files.Any(f => f.Name == fileName))
            {
                throw new ArgumentException("A file with the same name already exists.");
            }

            var newFile = new InMemoryVirtualFile(VirtualPathProvider, this)
            {
                FilePath = VirtualPathProvider.CombineVirtualPath(this.VirtualPath, fileName),
                FileName = fileName,
                ByteContents = new byte[0],
            };
            var stream = new InMemoryStream((contents) => newFile.ByteContents = contents);

            this.files.Add(newFile);

            return stream;
        }