/// <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); }
/// <summary> /// Returns additional required ObjC import directives. /// </summary> /// <param name="facet"></param> /// <returns></returns> public List <string> ObjCImportDirectives(CodeFacet facet, bool filter = true) { 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; string importStr = null; if (!string.IsNullOrEmpty(objCType)) { // we only need to import types defined in the current assembly. // other types will be imported via their own assembly's header if (AssemblyFacet.DefinesFacetType(facet.Type)) { // if the type is an enum if (facet.IsEnum) { objCType = facet.ObjCFacet.Type; importStr = $"#import \"{objCType}.h\""; imports.Add(importStr); } } } // forward declare objC facet types for all children List <CodeFacet> children = facet.Children(); foreach (CodeFacet child in children) { imports.AddRange(ObjCImportDirectives(child, false)); } // remove duplicates imports = imports.Distinct().ToList(); imports.Sort(); // the filter ensures that the import list doesn't include // the header that the import directives will be inserted into if (filter && importStr != null) { imports.Remove(importStr); } return(imports); }