private CodeTypeReference buildCodeTypeReference(InterfaceSignature isig,
                                                         IList <string> dependency_list,
                                                         IList <string> usings_list)
        {
            string[] parts      = isig.the_interface.Class_name.Split('.');
            string   class_name = parts[parts.Length - 1];


            CodeTypeReference slice_accessor_type = new CodeTypeReference(class_name + (isig.the_interface.Class_nargs == 0 ? "" : "`" + isig.the_interface.Class_nargs));

            dependency_list.Add(LoaderApp.buildDllName(isig.package_path, isig.the_interface.Assembly_string) + ".dll");

            if (!usings_list.Contains(isig.package_path))
            {
                usings_list.Add(isig.package_path);
            }

            slice_accessor_type.Options &= CodeTypeReferenceOptions.GenericTypeParameter;

            IList <InterfaceParameter> ip_list = BackEnd.ipdao.list(isig.the_interface.Id_abstract, isig.the_interface.Id_interface);

            IDictionary <String, CodeTypeReference> type_argument_list = new Dictionary <String, CodeTypeReference>();

            foreach (KeyValuePair <string, InterfaceSignature> isig_ in isig.parameters)
            {
                CodeTypeReference slice_accessor_arg_type;
                string            par_id = isig_.Key;
                if (isig.varId.ContainsKey(par_id))
                {
                    string var_id = isig.varId[isig_.Key];
                    slice_accessor_arg_type = new CodeTypeReference(var_id);
                }
                else
                {
                    slice_accessor_arg_type = buildCodeTypeReference(isig_.Value, dependency_list, usings_list);
                }
                // slice_accessor_type.TypeArguments.Add(slice_accessor_arg_type);
                type_argument_list.Add(par_id, slice_accessor_arg_type);
            }

            foreach (InterfaceParameter ip in ip_list)
            {
                slice_accessor_type.TypeArguments.Add(type_argument_list[ip.ParId]);
            }

            return(slice_accessor_type);
        }
        private CodeCompileUnit createCompileUnit(string package_path, string unit_class_name, out string[] dependencies)
        {
            IList <string> dependency_list = new List <string>();
            IList <string> usings_list     = new List <string>();

            CodeCompileUnit compileUnit = new CodeCompileUnit();

            #region namespace

            AbstractComponentFunctor acf = BackEnd.acfdao.retrieve(id_abstract);
            Interface i = BackEnd.idao.retrieve(id_abstract, id_interface);

            CodeNamespace globalNamespace = new CodeNamespace();
            compileUnit.Namespaces.Add(globalNamespace);

            CodeNamespace ns = new CodeNamespace(package_path);
            compileUnit.Namespaces.Add(ns);

            #endregion

            #region class

            IDictionary <string, int> par_order;
            InterfaceSignature        interface_type_descriptor = createSliceAccessorType(i, out par_order);
            CodeTypeReference         type_ref = buildCodeTypeReference(interface_type_descriptor, dependency_list, usings_list);

            string[] ss = i.Class_name.Split(new char[] { '.' });

            string unit_interface_name = ss[ss.Length - 1];
            //string unit_class_name = unit_interface_name + wrapper_source_name_suffix;
            CodeTypeDeclaration unit_class = new CodeTypeDeclaration(unit_class_name);
            ns.Types.Add(unit_class);

            #region class / inheritance

            unit_class.BaseTypes.Add("br.ufc.pargo.hpe.ConnectorImpl.IConnectorImpl");
            unit_class.BaseTypes.Add(type_ref);

            dependency_list.Add(LoaderApp.buildDllName(acf.Library_path, i.Assembly_string) + ".dll");
            dependency_list.Add("DGAC.dll");

            #endregion


            #region class / type parameters

            unit_class.TypeParameters.AddRange(createContextParameters(interface_type_descriptor, par_order, dependency_list, usings_list));

            #endregion

            #region class / public slice accessors

            IList <Slice> slice_list = BackEnd.sdao.listByInterface(id_abstract, id_interface);

            foreach (Slice s in slice_list)
            {
                if (s.isPublic())
                {
                    string slice_accessor_name = s.PortName;

                    InterfaceSignature isig_slice          = interface_type_descriptor.slice_types[slice_accessor_name];
                    CodeTypeReference  slice_accessor_type = buildCodeTypeReference(isig_slice, dependency_list, usings_list);

                    CodeMemberField slice_accessor_field = createSliceAccessorField(slice_accessor_name.ToLower(), slice_accessor_type);
                    unit_class.Members.Add(slice_accessor_field);

                    CodeMemberProperty slice_accessor_property = createSliceAccessorProperty(slice_accessor_name, slice_accessor_type);
                    unit_class.Members.Add(slice_accessor_property);
                }
            }

            #endregion

            #region class / actions and condition

            IList <InterfaceAction> action_list = BackEnd.iadao.list(id_abstract, id_interface);

            foreach (InterfaceAction ia in action_list)
            {
                if (ia.IsCondition)
                {
                    unit_class.Members.Add(createConditionMethod(ia.Id_action));
                }
                else
                {
                    if (!ia.Id_action.Equals("main"))
                    {
                        unit_class.Members.Add(createActionMethod(ia.Id_action));
                    }
                    else
                    {
                        // The default method "main" is pre-defined in the IConnectorImpl super class.
                    }
                }
            }
            #endregion


            #region using dependencies


            foreach (string using_reference in usings_list)
            {
                CodeNamespaceImport import = new CodeNamespaceImport();
                import.Namespace = using_reference;
                globalNamespace.Imports.Add(import);
            }

            #endregion

            #endregion

            dependencies = new string[dependency_list.Count];
            dependency_list.CopyTo(dependencies, 0);

            return(compileUnit);
        }