コード例 #1
0
        protected override IVirtualFile AddFileToBackingDirectoryOrDefault(string fileName, byte[] contents)
        {
            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 = contents
            };

            this.files.Add(newFile);
            return(newFile);
        }
コード例 #2
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;
        }