ResolveType() public method

Gets the DOM type of the type.
public ResolveType ( IType type ) : IType
type IType
return IType
        /// <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;
        }
        protected virtual CodeCompileUnit GenerateCodeCompileUnit(ProjectTypeCache cache, String defaultNamespace, String className, IEnumerable<IBPartialClassDescription> enumerable)
        {
            // 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 enumerable.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 enumerable.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);

            return ccu;
        }