public static FunctionSelector Get(string language) { FunctionSelector retVal = null; switch (language) { case "C#": retVal = new FunctionSelectorCSharp(); break; case "VisualBasic": retVal = new FunctionSelectorVB(); break; default: retVal = new FunctionSelector(); break; } return(retVal); }
/// <summary> /// Adds the controls which form the code snippet. /// </summary> /// <param name="source">The source code.</param> /// <param name="language">The language in which the source code is written.</param> protected virtual void RenderCode(string source, string language) { HighlighterBase highlighter = this.GetHighlighter(language); string parsedText = highlighter.Parse(source); string[] lines = parsedText.Replace("\r", String.Empty).Split('\n'); // Find the placeholders for the line numbers and source lines. Control templatedOutLineControl = new SourceHeaderItem(highlighter.FullName, lines.Length); this.Controls.Add(templatedOutLineControl); this.codeLayoutTemplate.InstantiateIn(templatedOutLineControl); PlaceHolder lineNumberPlaceHolder = this.FindLineNumberPlaceHolder(templatedOutLineControl); PlaceHolder sourceLinePlaceHolder = this.FindSourceLinePlaceHolder(templatedOutLineControl); FunctionSelector selector = FunctionSelectorFactory.Get(language); selector.FunctionName = FunctionName; if (lineNumberPlaceHolder != null || sourceLinePlaceHolder != null) { Control templatedLineNumberControl, templatedSourceLineControl, separatorControl; for (int i = 0; i < lines.Length; i++) { int lineNumber = (i + 1); if (lineNumber >= _StartLineNumber && lineNumber <= _EndLineNumber) { string line = lines[i]; if (selector.IsLineBelongingToRequiredFunction(line)) { if (lineNumberPlaceHolder != null && this.lineNumberTemplate != null) { // Parse line number. templatedLineNumberControl = new SourceItem(lineNumber, lines.Length, line); this.lineNumberTemplate.InstantiateIn(templatedLineNumberControl); lineNumberPlaceHolder.Controls.Add(templatedLineNumberControl); if (lineNumber < lines.Length && this.separatorTemplate != null) { separatorControl = new SeparatorItem(); this.separatorTemplate.InstantiateIn(separatorControl); lineNumberPlaceHolder.Controls.Add(separatorControl); } } if (sourceLinePlaceHolder != null && this.sourceLineTemplate != null) { // Parse source line. templatedSourceLineControl = new SourceItem(lineNumber, lines.Length, line); this.sourceLineTemplate.InstantiateIn(templatedSourceLineControl); sourceLinePlaceHolder.Controls.Add(templatedSourceLineControl); if (lineNumber < lines.Length && this.separatorTemplate != null) { separatorControl = new SeparatorItem(); this.separatorTemplate.InstantiateIn(separatorControl); sourceLinePlaceHolder.Controls.Add(separatorControl); } } } } } } templatedOutLineControl.DataBind(); }