public string Export(ScriptExportType exportType)
        {
            if (exportType.DeclaringType != null)
            {
                throw new NotSupportedException("You can export only topmost types");
            }

            if (IsBuiltInType(exportType))
            {
                return(null);
            }

            string subPath        = GetExportSubPath(exportType);
            string filePath       = Path.Combine(m_exportPath, subPath);
            string uniqueFilePath = ToUniqueFileName(filePath);
            string directory      = Path.GetDirectoryName(uniqueFilePath);

            if (!DirectoryUtils.Exists(directory))
            {
                DirectoryUtils.CreateVirtualDirectory(directory);
            }

            using (Stream fileStream = FileUtils.CreateVirtualFile(uniqueFilePath))
            {
                using (StreamWriter writer = new InvariantStreamWriter(fileStream, new UTF8Encoding(false)))
                {
                    exportType.Export(writer);
                }
            }
            AddExportedType(exportType);
            return(uniqueFilePath);
        }
        private static string GetExportSubPath(ScriptExportType type)
        {
            string typeName = type.NestedName;
            int    index    = typeName.IndexOf('<');

            if (index >= 0)
            {
                string normalName = typeName.Substring(0, index);
                typeName = normalName + $".{typeName.Count(t => t == ',') + 1}";
            }
            return(GetExportSubPath(type.Module, type.Namespace, typeName));
        }
        public string GetTypeNestedName(ScriptExportType relativeType)
        {
            string typeName = TypeName;

            if (DeclaringType == null)
            {
                return(TypeName);
            }
            if (relativeType == DeclaringType)
            {
                return(TypeName);
            }
            string declaringName = NestType.GetTypeNestedName(relativeType);

            return($"{declaringName}.{typeName}");
        }
        private void AddExportedType(ScriptExportType exportType)
        {
            m_exported.Add(exportType.FullName);
            foreach (ScriptExportEnum nestedEnum in exportType.NestedEnums)
            {
                m_exported.Add(nestedEnum.FullName);
            }
            foreach (ScriptExportDelegate @delegate in exportType.Delegates)
            {
                m_exported.Add(@delegate.FullName);
            }

            foreach (ScriptExportType nestedType in exportType.NestedTypes)
            {
                AddExportedType(nestedType);
            }
        }
 private static bool IsBuiltInType(ScriptExportType type)
 {
     return(IsBuiltinLibrary(type.Module));
 }