// // ObjCValueToManaged // // Return an ObjC expression that converts an ObjC object to its corresponding managed representation // public string ObjCValueToManaged(string objCVarName, string objCTypeDecl, CodeFacet managedFacet) { string exp = null; // extract type info in a format suitable for association string managedType = ManagedTypeForAssociation(managedFacet); // if type is an enum then use its underlying type if (managedFacet.IsEnum) { managedType = managedFacet.UnderlyingType; } // retrieve an ObjCTypeAssociation for the given managedType string key = ObjCTypeAssociation.UniqueTypeName(objCTypeDecl, managedType); if (ManagedTypeAssociations.ContainsKey(key)) { ManagedTypeAssociation managedTypeAssoc = ManagedTypeAssociations[key]; ObjCTypeAssociation objCTypeAssoc = ObjCTypeAssociations[managedType]; // use the value object format specifier if available string setterFormat = objCTypeAssoc.SetterFormat; if (setterFormat != null) { if (managedFacet.IsPointer) { setterFormat = "&{0}"; } exp = string.Format(setterFormat, objCVarName); } // use custom method else if (objCTypeAssoc.SetterMethod != null) { string methodName = objCTypeAssoc.SetterMethod; Type type = GetType(); MethodInfo method = type.GetMethod(methodName); if (method != null) { exp = (string)method.Invoke(this, new object[] { objCVarName, objCTypeDecl }); } } } // no ObjC expression defined. // generate default object representation expression. if (exp == null) { if (ObjCRepresentationIsPrimitive(managedFacet)) { exp = string.Format("&{0}", objCVarName); } else { exp = string.Format("[{0} monoObject]", objCVarName); } } return(exp); }
// // AssociateTypes() // void AssociateTypes(ManagedTypeAssociation managedTA, ObjCTypeAssociation objcTA) { objcTA.ManagedTypeAssociate = managedTA; // 1:1 association from managed type to objc type // the managed type name key is undecorated ObjCTypeAssociations.Add(managedTA.ManagedType, objcTA); // 1:N association from objc declaration to managed type. // hence we qualify the objc declaration with the managed type name. string objCKey = objcTA.UniqueTypeNameForManagedType(managedTA.ManagedType); ManagedTypeAssociations.Add(objCKey, managedTA); }