Projbook.Extension.DefaultSnippetExtractor.Extract C# (CSharp) Méthode

Extract() public méthode

Extracts a snippet.
fileSystemInfo
public Extract ( string fullFilename, string pattern ) : string
fullFilename string The full filename (with path) to load and to extract the snippet from.
pattern string The extraction pattern, never used for this implementation.
Résultat string
        public virtual string Extract(string fullFilename, string pattern)
        {
            if(string.IsNullOrEmpty(fullFilename))
            {
                throw new ArgumentNullException(nameof(fullFilename));
            }
            return this.LoadFile(fullFilename) ?? string.Empty;
        }

Usage Example

        public void ExtractSnippet()
        {
            // Declare content
            const string content =
            @"Some
            Content
            Here";
            // Mock file system
            IFileSystem fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>
            {
                { "Content.txt", new MockFileData(content) }
            });

            // Run the extraction
            DefaultSnippetExtractor extractor = new DefaultSnippetExtractor();
            FileInfoBase fileInfoBase = fileSystem.FileInfo.FromFileName("Content.txt");
            Extension.Model.PlainTextSnippet snippet = extractor.Extract(fileInfoBase, null) as Extension.Model.PlainTextSnippet;

            // Load the expected file content
            MemoryStream memoryStream = new MemoryStream();
            using (var fileReader = new StreamReader(fileInfoBase.OpenRead()))
            using (var fileWriter = new StreamWriter(memoryStream))
            {
                fileWriter.Write(fileReader.ReadToEnd());
            }

            // Assert
            Assert.AreEqual(content, snippet.Text);
        }
All Usage Examples Of Projbook.Extension.DefaultSnippetExtractor::Extract
DefaultSnippetExtractor