コード例 #1
0
        /// <summary>
        /// Returns all ObjC forward class and protocol declarations required to fully represent the facet.
        /// </summary>
        /// <param name="facet"></param>
        /// <returns></returns>
        public List <string> ObjCForwardDeclarations(CodeFacet facet)
        {
            List <string> imports = new List <string>();

            if (!Config.GenerateFacetBinding(facet))
            {
                return(imports);
            }

            // objC type
            // note that a constructor has no return type
            string objCType = facet.ObjCFacet.Type;

            if (!string.IsNullOrEmpty(objCType))
            {
                // if the type is a generic parameter
                if (facet.IsGenericParameterOrRef())
                {
                    objCType = "System_Object";
                }

                string import = String.Format("@class {0};", objCType);
                imports.Add(import);

                if (facet.IsArray == true)
                {
                    import = String.Format("@class {0};", facet.ObjCFacet.BaseType);
                    imports.Add(import);
                }

                if (facet.GetType() == typeof(InterfaceFacet) || facet.IsInterface)
                {
                    import = String.Format("@protocol {0}_;", objCType);
                    imports.Add(import);

                    import = String.Format("@protocol {0};", objCType);
                    imports.Add(import);
                }
            }

            // forward declare objC facet types for all children
            List <CodeFacet> children = facet.Children();

            foreach (CodeFacet child in children)
            {
                imports.AddRange(ObjCForwardDeclarations(child));
            }

            // return a distinct list to remove duplicates
            imports = imports.Distinct().ToList();
            imports.Sort();
            return(imports);
        }
コード例 #2
0
        //
        // ObjCTypeDeclFromManagedFacet()
        //
        public string ObjCTypeDeclFromManagedFacet(CodeFacet managedFacet, bool allowObjCTypeAssociation = true)
        {
            string decl = "";

            // if the facet represents a generic parameter (or ref) then we
            // won't know the actual type until runtime, so we default to the System_Object;
            if (managedFacet.IsGenericParameterOrRef())
            {
                decl = "System_Object *";
                return(decl);
            }

            string managedType = ManagedTypeForAssociation(managedFacet);

            if (managedType == null)
            {
                return("????");
            }

            if (allowObjCTypeAssociation && ObjCTypeAssociations.ContainsKey(managedType))
            {
                decl = ObjCTypeAssociations[managedType].ObjCTypeDecl;

                if (managedFacet.IsPointer)
                {
                    decl += " *";
                }
            }
            else
            {
                // canonical type name.
                decl = ObjCIdentifierFromManagedIdentifier(managedType);

                if (managedFacet.IsEnum)
                {
                    decl = "enum" + decl;
                }
                else
                {
                    decl += " *";
                }
            }

            return(decl);
        }