Append() public method

public Append ( string text, int lineNumber ) : void
text string
lineNumber int
return void
        public Sample Format(IFileReference file, string languageClass = null)
        {
            var snippet = new Sample(file.Path)
            {
                Language = languageClass ?? "lang-" + Path.GetExtension(file.Path).Replace(".", "")
            };

            file.ReadContents(stream =>
            {
                using (var reader = new StreamReader(stream))
                {
                    int lineNumber = 0;

                    string line;
                    while ((line = reader.ReadLine()) != null)
                    {
                        lineNumber++;

                        if (line.Contains(Samples.SAMPLE) || line.Contains(Samples.END))
                        {
                            snippet.Append(string.Empty, lineNumber);
                        }
                        else
                        {
                            snippet.Append(line, lineNumber);
                        }
                    }
                }
            });



            return(snippet);
        }
        public Sample Format(IFileReference file, string languageClass = null)
        {
            var snippet = new Sample(file.Path){
                Language = languageClass ?? "lang-" + Path.GetExtension(file.Path).Replace(".", "")
            };

            file.ReadContents(stream =>
            {
                using (var reader = new StreamReader(stream))
                {
                    int lineNumber = 0;

                    string line;
                    while ((line = reader.ReadLine()) != null)
                    {
                        lineNumber++;

                        if (line.Contains(Samples.SAMPLE) || line.Contains(Samples.END))
                        {
                            snippet.Append(string.Empty, lineNumber);
                        }
                        else
                        {
                            snippet.Append(line, lineNumber);
                        }
                    }
                }
            });



            return snippet;
        }
        public void level_indention()
        {
            var sample = new Sample("something");
            sample.Append("    something", 5);
            sample.Append("        else", 6);

            sample.Text.ShouldBe(@"something{0}    else{0}".ToFormat(Environment.NewLine).TrimStart());
        }
Beispiel #4
0
        private void lookForNewSnippet(string text, int lineNumber)
        {
            var name = _scanner.DetermineName(text);

            if (name.IsNotEmpty())
            {
                FoundSamples = true;

                var sample = new Sample(name)
                {
                    Language = _scanner.Language,
                    File     = _file.Path
                };

                _readAction = (txt, num) =>
                {
                    if (_scanner.IsAtEnd(txt))
                    {
                        _cache.AddOrReplace(sample);
                        _readAction = lookForNewSnippet;
                    }
                    else
                    {
                        if (!txt.TrimStart().StartsWith("///"))
                        {
                            sample.Append(txt, num);
                        }
                    }
                };
            }
        }
        private void lookForNewSnippet(string text, int lineNumber)
        {
            var name = _scanner.DetermineName(text);

            if (name.IsNotEmpty())
            {
                FoundSamples = true;

                var sample = new Sample(name){
                    Language = _scanner.Language,
                    File = _file.Path
                };

                _readAction = (txt, num) =>
                {
                    if (_scanner.IsAtEnd(txt))
                    {
                        _cache.AddOrReplace(sample);
                        _readAction = lookForNewSnippet;
                    }
                    else
                    {
                        sample.Append(txt, num);
                    }
                };
            }
        }
        public void append()
        {
            var sample = new Sample("the sample");
            sample.Append("something", 5);

            sample.Text.ShouldBe("something" + Environment.NewLine);
            sample.Start.ShouldBe(5);
            sample.End.ShouldBe(5);

            sample.Append("else", 6);
            sample.Append("and more", 7);

            sample.Start.ShouldBe(5);
            sample.End.ShouldBe(7);

            sample.Text.ShouldBe(@"something{0}else{0}and more{0}".ToFormat(Environment.NewLine).TrimStart());
            
        }