Example #1
0
        /// <summary>
        /// Sets up exported file dummy
        /// </summary>
        /// <param name="fileName">File name</param>
        /// <returns>Exported file dummy</returns>
        public ExportedFile CreateExportedFile(string fileName = null)
        {
            if (!Hierarchical && fileName == TargetFile)
            {
                fileName = null;
            }
            IEnumerable <Type> types = null;

            if (!string.IsNullOrEmpty(fileName))
            {
                if (!TypesToFilesMap.ContainsKey(fileName))
                {
                    var allFiles = string.Join(", ", TypesToFilesMap.Keys);
                    throw new Exception("Current configuration does not contain file " + fileName + ", only " + allFiles);
                }

                types = new HashSet <Type>(TypesToFilesMap[fileName]);
            }
            else
            {
                types = _allTypesHash;
            }
            var typesHash = new HashSet <Type>(types.Where(d => Project.Blueprint(d).ThirdParty == null));

            ExportedFile ef = new ExportedFile(typesHash, fileName, _globalReferences.Duplicate(), this);

            return(ef);
        }
Example #2
0
        /// <summary>
        /// Sets up exported file dummy
        /// </summary>
        /// <param name="fileName">File name</param>
        /// <returns>Exported file dummy</returns>
        public ExportedFile SetupExportedFile(string fileName = null)
        {
            if ((!_context.Hierarchical) && fileName == _context.TargetFile)
            {
                fileName = null;
            }
            IEnumerable <Type> types = null;

            if (!string.IsNullOrEmpty(fileName))
            {
                if (!_typesToFilesMap.ContainsKey(fileName))
                {
                    var allFiles = string.Join(", ", _typesToFilesMap.Keys);
                    throw new Exception("Current configuration does not contain file " + fileName + ", only " + allFiles);
                }

                types = _typesToFilesMap[fileName];
            }

            ExportedFile ef = new ExportedFile
            {
                References           = GlobalReferences.Duplicate(),
                FileName             = fileName,
                AllTypesIsSingleFile = !_context.Hierarchical,
                TypesToExport        = _context.Hierarchical ? new HashSet <Type>(types) : _allTypesHash
            };

            ef.TypeResolver = new TypeResolver(_context, ef, ReferenceInspector);
            _context.Project.AddReferencesFromTypes(ef, _context.Global.UseModules);
            return(ef);
        }
        /// <summary>
        ///     Constructs new type resolver
        /// </summary>
        internal TypeResolver(ExportedFile file)
        {
            _file = file;

            _anyOrUnknown = _file.Context.Global.UnresolvedToUnknown
                        ? UnknownType
                        : AnyType;
        }
 public void Export(string fileName, ExportedFile file, ReferenceProcessorBase refProcessor = null)
 {
     using (var fs = GetTmpFile(fileName))
     {
         using (var tw = new StreamWriter(fs))
         {
             ExportCore(tw, file, refProcessor);
         }
     }
 }
 public void Export(string fileName, ExportedFile file)
 {
     using (var fs = GetTmpFile(fileName))
     {
         using (var tw = new StreamWriter(fs))
         {
             ExportCore(tw, file);
         }
     }
 }
 internal void AddReferencesFromTypes(ExportedFile file, bool useImports)
 {
     foreach (var type in file.TypesToExport)
     {
         AddTypeSpecificReferences(file, type);
         if (useImports)
         {
             AddTypeSpecificImports(file, type);
         }
     }
 }
Example #7
0
 /// <summary>
 /// <inheritdoc />
 /// </summary>
 public void Export(string fileName, ExportedFile file)
 {
     using (var fs = GetTmpFile(fileName))
     {
         using (var tw = new StreamWriter(fs))
         {
             tw.NewLine = Context.Global.NewLine;
             ExportCore(tw, file);
         }
     }
 }
 internal static void AddReferencesFromTypes(this ExportedFile file, bool useImports)
 {
     foreach (var type in file.TypesToExport)
     {
         file.AddTypeSpecificReferences(type);
         if (useImports)
         {
             file.AddTypeSpecificImports(type);
         }
     }
 }
        protected virtual void ExportCore(StreamWriter tw, ExportedFile file, ReferenceProcessorBase refProcessor = null)
        {
            var visitor = Context.Global.ExportPureTypings
                ? new TypingsExportVisitor(tw, Context.Global.TabSymbol, Context.Global.ReorderMembers)
                : new TypeScriptExportVisitor(tw, Context.Global.TabSymbol, Context.Global.ReorderMembers);

            WriteWarning(tw);

            var references = file.References.References;

            if (refProcessor != null)
            {
                references = refProcessor.FilterReferences(references, file);
                if (references == null)
                {
                    references = new RtReference[0];
                }
            }
            bool hasReferences = false;

            foreach (var rtReference in references)
            {
                visitor.Visit(rtReference);
                hasReferences = true;
            }

            var imports = file.References.Imports;

            if (refProcessor != null)
            {
                imports = refProcessor.FilterImports(imports, file);
                if (imports == null)
                {
                    imports = new RtImport[0];
                }
            }
            bool hasImports = false;

            foreach (var rtImport in imports)
            {
                visitor.Visit(rtImport);
                hasImports = true;
            }
            if (hasReferences || hasImports)
            {
                tw.WriteLine();
            }

            foreach (var fileNamespace in file.Namespaces)
            {
                visitor.Visit(fileNamespace);
            }
        }
        /// <summary>
        /// Internal implementation of file Export operation
        /// </summary>
        /// <param name="tw">Target stream</param>
        /// <param name="file">Exported file</param>
        protected virtual void ExportCore(StreamWriter tw, ExportedFile file)
        {
            var visitor =
                Context.Global.VisitorType == null
                    ? Context.Global.ExportPureTypings
                        ? new TypingsExportVisitor(tw, Context)
                        : new TypeScriptExportVisitor(tw, Context)
                    : (TextExportingVisitor)Activator.CreateInstance(Context.Global.VisitorType, new object[] { tw, Context });

            WriteWarning(tw);

            visitor.VisitFile(file);
        }
        private static void AddTypeSpecificReferences(this ExportedFile file, Type t)
        {
            var frefs = ConfigurationRepository.Instance.ReferenceAttributes;

            var fluentRefs = frefs.ContainsKey(t) ? frefs[t] : null;
            var typeRefs   = t.GetCustomAttributes <TsAddTypeReferenceAttribute>();

            foreach (var tsAddTypeReferenceAttribute in typeRefs)
            {
                if (tsAddTypeReferenceAttribute.Type != null)
                {
                    file.TypeResolver.ResolveTypeName(tsAddTypeReferenceAttribute.Type);
                }
                else
                {
                    file.References.AddReference(new RtReference()
                    {
                        Path = tsAddTypeReferenceAttribute.RawPath
                    });
                }
            }

            if (fluentRefs != null)
            {
                foreach (var tsAddTypeReferenceAttribute in fluentRefs)
                {
                    if (tsAddTypeReferenceAttribute.Type != null)
                    {
                        file.TypeResolver.ResolveTypeName(tsAddTypeReferenceAttribute.Type);
                    }
                    else
                    {
                        file.References.AddReference(new RtReference()
                        {
                            Path = tsAddTypeReferenceAttribute.RawPath
                        });
                    }
                }
            }
        }
        private void AddTypeSpecificReferences(ExportedFile file, Type t)
        {
            var fluentRefs = Blueprint(t).References;
            var typeRefs   = t.GetCustomAttributes <TsAddTypeReferenceAttribute>();

            foreach (var tsAddTypeReferenceAttribute in typeRefs)
            {
                if (tsAddTypeReferenceAttribute.Type != null)
                {
                    file.TypeResolver.ResolveTypeName(tsAddTypeReferenceAttribute.Type);
                }
                else
                {
                    file.References.AddReference(new RtReference()
                    {
                        Path = tsAddTypeReferenceAttribute.RawPath
                    });
                }
            }

            if (fluentRefs != null)
            {
                foreach (var tsAddTypeReferenceAttribute in fluentRefs)
                {
                    if (tsAddTypeReferenceAttribute.Type != null)
                    {
                        file.TypeResolver.ResolveTypeName(tsAddTypeReferenceAttribute.Type);
                    }
                    else
                    {
                        file.References.AddReference(new RtReference()
                        {
                            Path = tsAddTypeReferenceAttribute.RawPath
                        });
                    }
                }
            }
        }
        private void AddTypeSpecificImports(ExportedFile file, Type t)
        {
            var fluentImports = Blueprint(t).Imports;
            var typeImports   = t.GetCustomAttributes <TsAddTypeImportAttribute>();

            foreach (var tsAddTypeImportAttribute in typeImports)
            {
                file.References.AddImport(new RtImport()
                {
                    From = tsAddTypeImportAttribute.ImportSource, Target = tsAddTypeImportAttribute.ImportTarget, IsRequire = tsAddTypeImportAttribute.ImportRequire
                });
            }
            if (fluentImports != null)
            {
                foreach (var tsAddTypeImportAttribute in fluentImports)
                {
                    file.References.AddImport(new RtImport()
                    {
                        From = tsAddTypeImportAttribute.ImportSource, Target = tsAddTypeImportAttribute.ImportTarget, IsRequire = tsAddTypeImportAttribute.ImportRequire
                    });
                }
            }
        }
        protected virtual void ExportCore(StreamWriter tw, ExportedFile file)
        {
            var visitor = Context.Global.ExportPureTypings ? new TypingsExportVisitor(tw, Context.Global.TabSymbol) : new TypeScriptExportVisitor(tw, Context.Global.TabSymbol);

            WriteWarning(tw);
            foreach (var rtReference in file.References.References)
            {
                visitor.Visit(rtReference);
            }

            foreach (var rtImport in file.References.Imports)
            {
                visitor.Visit(rtImport);
            }
            if (file.References.References.Any() || file.References.Imports.Any())
            {
                tw.WriteLine();
            }
            foreach (var fileNamespace in file.Namespaces)
            {
                visitor.Visit(fileNamespace);
            }
        }
        private static void AddTypeSpecificImports(this ExportedFile file, Type t)
        {
            var fimps         = ConfigurationRepository.Instance.ImportAttributes;
            var fluentImports = fimps.ContainsKey(t) ? fimps[t] : null;
            var typeImports   = t.GetCustomAttributes <TsAddTypeImportAttribute>();

            foreach (var tsAddTypeImportAttribute in typeImports)
            {
                file.References.AddImport(new RtImport()
                {
                    From = tsAddTypeImportAttribute.ImportSource, Target = tsAddTypeImportAttribute.ImportTarget, IsRequire = tsAddTypeImportAttribute.ImportRequire
                });
            }
            if (fluentImports != null)
            {
                foreach (var tsAddTypeImportAttribute in fluentImports)
                {
                    file.References.AddImport(new RtImport()
                    {
                        From = tsAddTypeImportAttribute.ImportSource, Target = tsAddTypeImportAttribute.ImportTarget, IsRequire = tsAddTypeImportAttribute.ImportRequire
                    });
                }
            }
        }
Example #16
0
 /// <summary>
 ///     Constructs new type resolver
 /// </summary>
 internal TypeResolver(ExportContext context, ExportedFile file, ReferenceInspector refInspector)
 {
     _context      = context;
     _file         = file;
     _refInspector = refInspector;
 }
 /// <summary>
 ///     Constructs new type resolver
 /// </summary>
 internal TypeResolver(ExportedFile file)
 {
     _file = file;
 }