/// <summary> /// Ensures that imports for specified type presents in specified file /// </summary> /// <param name="t">Type to import</param> /// <param name="typeName">Type name (probably overriden)</param> /// <returns>Import AST node or null if no import needed. Returns existing import in case if type is already imported</returns> internal RtImport EnsureImport(Type t, string typeName) { if (TypesToExport.Contains(t)) { return(null); } var bp = _context.Project.Blueprint(t); if (bp.ThirdParty != null) { foreach (var tpi in bp.ThirdPartyImports) { References.AddImport(tpi); } return(null); } if (AllTypesIsSingleFile) { return(null); } var relPath = GetRelativePathForType(t, FileName); if (string.IsNullOrEmpty(relPath)) { return(null); } RtImport result = null; if (References.StarImports.ContainsKey(relPath)) { return(References.StarImports[relPath]); } if (_context.Global.DiscardNamespacesWhenUsingModules) { var target = string.Format("{{ {0} }}", typeName); result = new RtImport() { From = relPath, Target = target }; References.AddImport(result); } else { var alias = Path.GetFileNameWithoutExtension(relPath); var target = string.Format("* as {0}", alias); result = new RtImport() { From = relPath, Target = target }; References.AddImport(result); } return(result); }
private void AddTypeSpecificImports(Type t) { var imports = _context.Project.Blueprint(t).Imports; foreach (var tsAddTypeImportAttribute in imports) { References.AddImport(tsAddTypeImportAttribute.ToImport()); } }