/// <summary> /// Retrieves an extension handler. /// </summary> /// <param name="fileName">Name of the file.</param> /// <returns>Source handler.</returns> public SourceHandler GetSourceHandler(string fileName) { string extension = GetExtension(fileName); SourceHandler handler = null; _sourceExtensionHandlers.TryGetValue(extension, out handler); return(handler); }
public void CreateTest() { string assemblyName = "NArrange.CSharp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"; SourceHandlerConfiguration configuration = new SourceHandlerConfiguration(); configuration.AssemblyName = assemblyName; SourceHandler handler = new SourceHandler(configuration); Assert.IsNotNull(handler.CodeParser, "Parser was not created."); Assert.IsNotNull(handler.CodeWriter, "Writer was not created."); }
/// <summary> /// Gets a boolean indicating whether or not the file is a /// recognized source file. /// </summary> /// <param name="fileName">File to test.</param> /// <returns>A boolean indicating whehther or not the file is recognized.</returns> private bool IsRecognizedSourceFile(string fileName) { bool recognized = false; SourceHandler handler = GetSourceHandler(fileName); if (handler != null) { recognized = IsRecognizedFile(fileName, handler.Configuration.SourceExtensions); } return(recognized); }
/// <summary> /// Parses code elements from the input file. /// </summary> /// <param name="inputFile">The input file.</param> /// <param name="text">The text of the input file.</param> /// <returns>Collection of parsed code elements.</returns> public ReadOnlyCollection <ICodeElement> ParseElements(string inputFile, string text) { ReadOnlyCollection <ICodeElement> elements = null; SourceHandler sourceHandler = GetSourceHandler(inputFile); if (sourceHandler != null) { ICodeElementParser parser = sourceHandler.CodeParser; if (parser != null) { parser.Configuration = _configuration; using (StringReader reader = new StringReader(text)) { elements = parser.Parse(reader); } } } return(elements); }
/// <summary> /// Initializes the manager from the configuration supplied /// during constuction. /// </summary> private void Initialize() { // // Load extension handlers // _projectExtensionHandlers = new Dictionary <string, ProjectHandler>( StringComparer.OrdinalIgnoreCase); _sourceExtensionHandlers = new Dictionary <string, SourceHandler>( StringComparer.OrdinalIgnoreCase); foreach (HandlerConfiguration handlerConfiguration in _configuration.Handlers) { switch (handlerConfiguration.HandlerType) { case HandlerType.Source: SourceHandlerConfiguration sourceConfiguration = handlerConfiguration as SourceHandlerConfiguration; SourceHandler sourceHandler = new SourceHandler(sourceConfiguration); foreach (ExtensionConfiguration extension in sourceConfiguration.SourceExtensions) { _sourceExtensionHandlers.Add(extension.Name, sourceHandler); } break; case HandlerType.Project: ProjectHandlerConfiguration projectConfiguration = handlerConfiguration as ProjectHandlerConfiguration; ProjectHandler projectHandler = new ProjectHandler(projectConfiguration); foreach (ExtensionConfiguration extension in projectConfiguration.ProjectExtensions) { _projectExtensionHandlers.Add(extension.Name, projectHandler); } break; default: throw new InvalidOperationException( string.Format( CultureInfo.InvariantCulture, "Unrecognized handler configuration {0}", handlerConfiguration)); } } }
/// <summary> /// Initializes the manager from the configuration supplied /// during constuction. /// </summary> private void Initialize() { // // Load extension handlers // _projectExtensionHandlers = new Dictionary<string, ProjectHandler>( StringComparer.OrdinalIgnoreCase); _sourceExtensionHandlers = new Dictionary<string, SourceHandler>( StringComparer.OrdinalIgnoreCase); foreach (HandlerConfiguration handlerConfiguration in _configuration.Handlers) { switch (handlerConfiguration.HandlerType) { case HandlerType.Source: SourceHandlerConfiguration sourceConfiguration = handlerConfiguration as SourceHandlerConfiguration; SourceHandler sourceHandler = new SourceHandler(sourceConfiguration); foreach (ExtensionConfiguration extension in sourceConfiguration.SourceExtensions) { _sourceExtensionHandlers.Add(extension.Name, sourceHandler); } break; case HandlerType.Project: ProjectHandlerConfiguration projectConfiguration = handlerConfiguration as ProjectHandlerConfiguration; ProjectHandler projectHandler = new ProjectHandler(projectConfiguration); foreach (ExtensionConfiguration extension in projectConfiguration.ProjectExtensions) { _projectExtensionHandlers.Add(extension.Name, projectHandler); } break; default: throw new InvalidOperationException( string.Format( CultureInfo.InvariantCulture, "Unrecognized handler configuration {0}", handlerConfiguration)); } } }