Пример #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
        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 directory = Path.GetDirectoryName(filePath);

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

            using (FileStream file = FileUtils.OpenWrite(filePath))
            {
                using (StreamWriter writer = new StreamWriter(file))
                {
                    exportType.Export(writer);
                }
            }
            AddExportedType(exportType);
            return(filePath);
        }
Пример #3
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));
        }
Пример #4
0
        private static bool IsBuiltInType(ScriptExportType type)
        {
            if (IsDotNetLibrary(type.Module))
            {
                return(true);
            }
            if (IsUnityLibrary(type.Module))
            {
                return(true);
            }

            return(false);
        }
Пример #5
0
        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}");
        }
Пример #6
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);
            }
        }
Пример #7
0
		public string GetTypeNestedName(ScriptExportType relativeType)
		{
			if(relativeType == null)
			{
				return Name;
			}
			if (ScriptType.IsEngineObject(Namespace, Name))
			{
				return $"{Namespace}.{Name}";
			}
			if (DeclaringType == null)
			{
				return TypeName;
			}
			if (relativeType == DeclaringType)
			{
				return TypeName;
			}

			string declaringName = DeclaringType.GetTypeNestedName(relativeType);
			return $"{declaringName}.{TypeName}";
		}
Пример #8
0
        public string GetTypeNestedName(ScriptExportType relativeType)
        {
            if (relativeType == null)
            {
                return(NestedName);
            }
            if (SerializableType.IsEngineObject(Namespace, NestedName))
            {
                return($"{Namespace}.{NestedName}");
            }
            if (DeclaringType == null)
            {
                return(TypeName);
            }
            if (relativeType == DeclaringType)
            {
                return(TypeName);
            }

            string declaringName = NestType.GetTypeNestedName(relativeType);

            return($"{declaringName}.{TypeName}");
        }
Пример #9
0
        public ScriptExportType CreateExportType(TypeReference type)
        {
            ScriptExportType exportType = RetrieveType(type);

            return(exportType);
        }
Пример #10
0
 private static bool IsBuiltInType(ScriptExportType type)
 {
     return(IsBuiltInLibrary(type.Module));
 }