private void ExtractReferences() { if (_isAnalyzed) { return; } _context.Documentation = new DocumentationManager(_context.GenerateDocumentation ? _context.DocumentationFilePath : null, _context.Warnings); var fluentConfigurationPresents = _context.ConfigurationMethod != null; if (fluentConfigurationPresents) { var configurationBuilder = new ConfigurationBuilder(); _context.ConfigurationMethod(configurationBuilder); _configurationRepository = configurationBuilder.Build(); ConfigurationRepository.Instance = _configurationRepository; foreach (var additionalDocumentationPath in _configurationRepository.AdditionalDocumentationPathes) { _context.Documentation.CacheDocumentation(additionalDocumentationPath, _context.Warnings); } } _allTypes = _context.SourceAssemblies .SelectMany(c => c.GetTypes().Where(d => d.GetCustomAttribute <TsAttributeBase>(false) != null)) .Union(ConfigurationRepository.Instance.AttributesForType.Keys).Distinct() .ToList(); _allTypesHash = new HashSet <Type>(_allTypes); if (_context.Hierarchical) { foreach (var type in _allTypesHash) { ConfigurationRepository.Instance.AddFileSeparationSettings(type); } } _context.SourceAssemblies.Where(c => c.GetCustomAttributes <TsReferenceAttribute>().Any()) .SelectMany(c => c.GetCustomAttributes <TsReferenceAttribute>()) .Select(c => string.Format("/// <reference path=\"{0}\"/>", c.Path)) .Union( ConfigurationRepository.Instance.References.Select( c => string.Format("/// <reference path=\"{0}\"/>", c))) .ToList() .ForEach(a => _referenceBuilder.AppendLine(a)); _context.References = _referenceBuilder.ToString(); _isAnalyzed = true; }
/// <summary> /// Initializes TS exporter. Reads all types configuration, applies fluent configuration, resolves references /// </summary> public void Initialize() { if (_isInitialized) { return; } // 1st step - searching and processing [TsGlobal] attribute var tsGlobal = _context.SourceAssemblies.Select(c => c.GetCustomAttribute <TsGlobalAttribute>()) .Where(c => c != null) .OrderByDescending(c => c.Priority) .FirstOrDefault(); ApplyTsGlobal(tsGlobal, _context.Global); // 2nd step - searching and processing fluent configuration var fluentConfigurationPresents = _context.ConfigurationMethod != null; if (fluentConfigurationPresents) { var configurationBuilder = new ConfigurationBuilder(_context); _context.ConfigurationMethod(configurationBuilder); } _context.Documentation = new DocumentationManager(_context.Global.GenerateDocumentation ? _context.DocumentationFilePath : null, _context.Warnings); foreach (var additionalDocumentationPath in _context.Project.AdditionalDocumentationPathes) { _context.Documentation.CacheDocumentation(additionalDocumentationPath, _context.Warnings); } _allTypes = _context.SourceAssemblies .SelectMany(c => c._GetTypes(_context.Warnings).Where(d => d.GetCustomAttribute <TsAttributeBase>(false) != null)) .Union(_context.Project.BlueprintedTypes).Distinct() .ToList(); _allTypesHash = new HashSet <Type>(_allTypes); ReferenceInspector = new ReferenceInspector(_context, _allTypesHash); if (_context.Hierarchical) { foreach (var type in _allTypesHash) { _context.Project.AddFileSeparationSettings(type); } } GlobalReferences = ReferenceInspector.InspectGlobalReferences(); _context.Generators = new GeneratorManager(_context); if (!_context.Hierarchical) { _typesToFilesMap = new Dictionary <string, IEnumerable <Type> >(); } else { _typesToFilesMap = _allTypes.GroupBy(c => ReferenceInspector.GetPathForType(c, stripExtension: false)) .ToDictionary(c => c.Key, c => c.AsEnumerable()); } _isInitialized = true; }