예제 #1
0
        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);
        }
예제 #2
0
        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}");
        }
예제 #4
0
        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);
            }
        }
예제 #5
0
 private static bool IsBuiltInType(ScriptExportType type)
 {
     return(IsBuiltinLibrary(type.Module));
 }