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 (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } using (FileStream file = File.OpenWrite(filePath)) { using (StreamWriter writer = new StreamWriter(file)) { exportType.Export(writer); } } AddExportedType(exportType); return(filePath); }
private static string GetExportSubPath(ScriptExportType type) { string typeName = type.Name; int index = typeName.IndexOf('<'); if (index >= 0) { typeName = typeName.Substring(0, index); typeName += $".{typeName.Count(t => t == ',') + 1}"; } return(GetExportSubPath(type.Module, type.Namespace, typeName)); }
private static bool IsBuiltInType(ScriptExportType type) { if (IsDotNetLibrary(type.Module)) { return(true); } if (IsUnityLibrary(type.Module)) { //return true; } return(false); }
private string GetTypeNestedName(ScriptExportType type) { if (type.DeclaringType == null) { return(type.Name); } if (type == DeclaringType) { return(type.Name); } string declaringName = GetTypeNestedName(type.DeclaringType); return($"{declaringName}.{type.Name}"); }
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 string GetTypeNestedName(ScriptExportType type) { if (ScriptType.IsEngineObject(type.Namespace, type.Name)) { return($"{type.Namespace}.{type.Name}"); } if (type.DeclaringType == null) { return(type.Name); } if (type.DeclaringType == DeclaringType) { return(type.Name); } string declaringName = GetTypeNestedName(type.DeclaringType); return($"{declaringName}.{type.Name}"); }
protected bool HasMember(ScriptExportType type, string name) { foreach (ScriptExportField field in type.Fields) { if (field.Name == Name) { return(true); } } if (type.Base == null) { return(HasMemberInner(name)); } else { return(HasMember(type.Base, name)); } }
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}"); }
public ScriptExportType CreateExportType(TypeReference type) { ScriptExportType exportType = RetrieveType(type); return(exportType); }