internal void GenerateDesignerCode (CodeBehindWriter writer, ProjectFile xibFile, ProjectFile designerFile) { var ccu = Generate (xibFile, writer.Provider, writer.GeneratorOptions); writer.WriteFile (designerFile.FilePath, ccu); }
public static BuildResult UpdateDesignerFile ( CodeBehindWriter writer, DotNetProject project, ProjectFile file, ProjectFile designerFile ) { var result = new BuildResult (); //parse the ASP.NET file var parsedDocument = TypeSystemService.ParseFile (project, file.FilePath).Result as WebFormsParsedDocument; if (parsedDocument == null) { result.AddError (string.Format ("Failed to parse file '{0}'", file.Name)); return result; } //TODO: ensure type system is up to date CodeCompileUnit ccu; result.Append (GenerateCodeBehind (project, designerFile.FilePath, parsedDocument, out ccu)); if (ccu != null) { writer.WriteFile (designerFile.FilePath, ccu); } return result; }
/// <summary> /// Generates the design code for an Interface Builder file. /// </summary> /// <param name = "resolver">The type resolver.</param> /// <param name = "writer">The writer.</param> /// <param name = "className">Name of the class.</param> /// <param name = "enumerable">The class descriptions.</param> /// <returns>The path to the designer file.</returns> public FilePath GenerateCodeBehindCode(ProjectTypeCache cache, CodeBehindWriter writer, String className, IEnumerable<IIBClassDescriptor> descriptors) { FilePath designerFile = null; String defaultNamespace; MonobjcProject project = cache.Project; IDELogger.Log ("BaseCodeBehindGenerator::GenerateCodeBehindCode -- Generate designer code for '{0}'", className); IType type = cache.ResolvePartialType (className); FilePath mainFile = cache.GetMainFile (type); if (mainFile != FilePath.Null) { if (mainFile.Extension == ".dll") { IDELogger.Log ("BaseCodeBehindGenerator::GenerateCodeBehindCode -- Skipping '{0}' as it comes from a DLL", className); return FilePath.Null; } if (!cache.IsInProject (type)) { IDELogger.Log ("BaseCodeBehindGenerator::GenerateCodeBehindCode -- Skipping '{0}' as it comes from another project", className); return FilePath.Null; } // The filname is based on the compilation unit parent folder and the type name FilePath parentDirectory = mainFile.ParentDirectory; FilePath filename = project.LanguageBinding.GetFileName (type.Name + Constants.DOT_DESIGNER); designerFile = parentDirectory.Combine (filename); defaultNamespace = type.Namespace; } else { // Combine the filename in the default directory FilePath parentDirectory = project.BaseDirectory; FilePath filename = project.LanguageBinding.GetFileName (className + Constants.DOT_DESIGNER); designerFile = parentDirectory.Combine (filename); defaultNamespace = project.GetDefaultNamespace (designerFile); } IDELogger.Log ("BaseCodeBehindGenerator::GenerateCodeBehindCode -- Put designer code in '{0}'", designerFile); // Create the compilation unit CodeCompileUnit ccu = new CodeCompileUnit (); CodeNamespace ns = new CodeNamespace (defaultNamespace); ccu.Namespaces.Add (ns); // Create the partial class CodeTypeDeclaration typeDeclaration = new CodeTypeDeclaration (className); typeDeclaration.IsClass = true; typeDeclaration.IsPartial = true; // List for import collection Set<String> imports = new Set<string> (); imports.Add ("Monobjc"); // Create fields for outlets); foreach (IBOutletDescriptor outlet in descriptors.SelectMany(d => d.Outlets)) { IType outletType = cache.ResolvePartialType (outlet.ClassName); outletType = outletType ?? cache.ResolvePartialType ("id"); outletType = outletType ?? cache.ResolveType (typeof(IntPtr)); IDELogger.Log ("BaseCodeBehindGenerator::GenerateCodeBehindCode -- Resolving outlet '{0}' of type '{1}' => '{2}'", outlet.Name, outlet.ClassName, outletType.FullName); imports.Add (outletType.Namespace); CodeTypeMember property = this.GenerateOutletProperty (outletType, outlet.Name); typeDeclaration.Members.Add (property); } // Create methods for exposed actions foreach (IBActionDescriptor action in descriptors.SelectMany(d => d.Actions)) { IType argumentType = cache.ResolvePartialType (action.Argument); argumentType = argumentType ?? cache.ResolvePartialType ("id"); argumentType = argumentType ?? cache.ResolveType (typeof(IntPtr)); IDELogger.Log ("BaseCodeBehindGenerator::GenerateCodeBehindCode -- Resolving action '{0}' of type '{1}' => '{2}'", action.Message, action.Argument, argumentType.FullName); imports.Add (argumentType.Namespace); CodeTypeMember exposedMethod = this.GenerateActionExposedMethod (action.Message, argumentType); typeDeclaration.Members.Add (exposedMethod); CodeTypeMember partialMethod = this.GenerateActionPartialMethod (action.Message, argumentType); typeDeclaration.Members.Add (partialMethod); } // Add namespaces CodeNamespaceImport[] namespaceImports = imports.Select (import => new CodeNamespaceImport (import)).ToArray (); ns.Imports.AddRange (namespaceImports); // Add the type ns.Types.Add (typeDeclaration); // Write the result writer.WriteFile (designerFile, ccu); return designerFile; }