private static void PopulateClass(TypeSafeDataUnit dataUnit, CodeTypeDeclaration container) { foreach (var nestedUnit in dataUnit.NestedUnits) { string className; if (!CompilerUtil.GetSafeNameAndVerifyNotDuplicate(nestedUnit.ClassName, container, out className)) { continue; } if (className == container.Name) { TSLog.LogWarning(LogCategory.Compile, Strings.Warning_NameCannotBeSameAsParent); className = "_" + className; // Check for duplicates again after having added the '_' if (!CompilerUtil.GetSafeNameAndVerifyNotDuplicate(className, container, out className)) { continue; } } var nestedContainer = CompilerUtil.CreateStaticType(className); PopulateClass(nestedUnit, nestedContainer); container.Members.Add(nestedContainer); } PopulateClassMembers(dataUnit, container); }
public CodeCompileUnit Compile(TypeSafeDataUnit dataUnit) { var compileUnit = new CodeCompileUnit(); compileUnit.UserData.Add(Strings.CompileUnitUserDataKey, dataUnit.FileName); CompilerUtil.WriteHeader(compileUnit); var ns = new CodeNamespace(Namespace); compileUnit.Namespaces.Add(ns); var className = CompilerUtil.GetSafeName(dataUnit.ClassName, false, false); if (className != dataUnit.ClassName) { TSLog.LogWarning(LogCategory.Compile, string.Format("Class name was modified to conform to C# standards ({0} -> {1})", dataUnit.ClassName, className)); } var container = CompilerUtil.CreateStaticType(className); CompilerUtil.AddTypeSafeTag(container); PopulateClass(dataUnit, container); ns.Types.Add(container); return(compileUnit); }
private void WriteFolder(CodeTypeDeclaration type, ResourceFolder folder) { ResourceCompilerUtil.WriteResources(type, folder); foreach (var f in folder.Folders) { var c = CompilerUtil.CreateStaticType(CompilerUtil.GetSafeName(f.Name)); WriteFolder(c, f); type.Members.Add(c); } ResourceCompilerUtil.CreateGetContentsMethod(type); ResourceCompilerUtil.CreateGetContentsRecursiveMethod(type, folder); ResourceCompilerUtil.WriteGetContentsGenericMethod(type); ResourceCompilerUtil.WriteGetContentsRecursiveGenericMethod(type); ResourceCompilerUtil.WriteUnloadAllMethod(type); ResourceCompilerUtil.WriteUnloadAllRecursiveMethod(type); }
public CodeCompileUnit Compile(ResourceDatabase database) { var unit = new CodeCompileUnit(); unit.UserData.Add(Strings.CompileUnitUserDataKey, "Resources"); CompilerUtil.WriteHeader(unit); var ns = new CodeNamespace(Namespace); unit.Namespaces.Add(ns); var container = CompilerUtil.CreateStaticType(ClassName); CompilerUtil.AddTypeSafeTag(container); WriteFolder(container, database.RootFolder); ns.Types.Add(container); return(unit); }