Пример #1
0
        internal static MetadataItem GenerateYamlMetadata(Compilation compilation, IAssemblySymbol assembly = null, bool preserveRawInlineComments = false, string filterConfigFile = null, IReadOnlyDictionary <Compilation, IEnumerable <IMethodSymbol> > extensionMethods = null)
        {
            if (compilation == null)
            {
                return(null);
            }

            object visitorContext = new object();
            SymbolVisitorAdapter visitor;

            if (compilation.Language == "Visual Basic")
            {
                visitor = new SymbolVisitorAdapter(new CSYamlModelGenerator() + new VBYamlModelGenerator(), SyntaxLanguage.VB, compilation, preserveRawInlineComments, filterConfigFile, extensionMethods);
            }
            else if (compilation.Language == "C#")
            {
                visitor = new SymbolVisitorAdapter(new CSYamlModelGenerator() + new VBYamlModelGenerator(), SyntaxLanguage.CSharp, compilation, preserveRawInlineComments, filterConfigFile, extensionMethods);
            }
            else
            {
                Debug.Assert(false, "Language not supported: " + compilation.Language);
                Logger.Log(LogLevel.Error, "Language not supported: " + compilation.Language);
                return(null);
            }

            assembly = assembly ?? compilation.Assembly;
            MetadataItem item = assembly.Accept(visitor);

            return(item);
        }
Пример #2
0
        public MetadataItem Extract(ExtractMetadataOptions options)
        {
            var preserveRawInlineComments = options.PreserveRawInlineComments;
            var filterConfigFile          = options.FilterConfigFile;
            var extensionMethods          = options.ExtensionMethods;

            object visitorContext = new object();
            SymbolVisitorAdapter visitor;

            if (_compilation.Language == "Visual Basic")
            {
                visitor = new SymbolVisitorAdapter(new CSYamlModelGenerator() + new VBYamlModelGenerator(), SyntaxLanguage.VB, _compilation, preserveRawInlineComments, filterConfigFile, extensionMethods);
            }
            else if (_compilation.Language == "C#")
            {
                visitor = new SymbolVisitorAdapter(new CSYamlModelGenerator() + new VBYamlModelGenerator(), SyntaxLanguage.CSharp, _compilation, preserveRawInlineComments, filterConfigFile, extensionMethods);
            }
            else
            {
                Debug.Assert(false, "Language not supported: " + _compilation.Language);
                Logger.Log(LogLevel.Error, "Language not supported: " + _compilation.Language);
                return(null);
            }

            MetadataItem item = _assembly.Accept(visitor);

            return(item);
        }
Пример #3
0
        internal IAssemblySymbol VisitRoot(IAssemblySymbol assemblySymbol)
        {
            ISymbol result = assemblySymbol.Accept(this);

            if (result.GetType().Name != "SourceAssemblySymbol")
            {
                throw new InvalidOperationException($"Cannot convert {result.GetType()} to 'SourceAssemblySymbol'.");
            }

            return((IAssemblySymbol)result);
        }