コード例 #1
0
        /// <summary>
        /// Reads and reflects the given VB Classic text file into a usable form.
        /// </summary>
        /// <param name="partitionedFile">An instance of <see cref="VbPartitionedFile"/> representing the VB Classic module to reflect.</param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException"><paramref name="partitionedFile"/> was null.</exception>
        /// <exception cref="InvalidOperationException">There was no analyzer considered fitting for the underlying file.</exception>
        public static IVbModule GetReflectedModule(VbPartitionedFile partitionedFile)
        {
            if (partitionedFile == null)
            {
                throw new ArgumentNullException("partitionedFile");
            }

            if (Tokenizer == null)
            {
                throw new InvalidOperationException("No tokenizer defined for analyzing the file!");
            }

            IReadOnlyList <IToken> tokens = Tokenizer.GetTokens(partitionedFile.GetMergedContent());

            TokenStreamReader reader = new TokenStreamReader(tokens);

            IAnalyzer analyzer = null;

            if (!AnalyzerFactory.TryGetAnalyzerForFile(reader, out analyzer))
            {
                // TODO: Dedicated exception for this.
                throw new InvalidOperationException("Could not analyze the given file!");
            }

            reader.Rewind();

            return(analyzer.Analyze(reader));
        }