protected override void OnReloadType(ObjCType type) { if (type.Handle != IntPtr.Zero) { return; } type.Handle = Class.GetHandle(type.ExportedName); }
protected override void OnRegisterCategory(ObjCType type, ref List <Exception> exceptions) { if (type.Methods != null) { foreach (var method in type.Methods) { if (!RegisterMethod(method)) { AddException(ref exceptions, ErrorHelper.CreateError(4155, "Cannot register the method '{0}.{1}' with the selector '{2}' as a category method on '{3}' because Objective-C already has an implementation for this selector.", GetTypeFullName(type.Type), method.MethodName, method.Selector, type.ExportedName)); } } } }
protected override void OnRegisterType(ObjCType type) { type.Handle = Class.GetHandle(type.ExportedName); if (type.Handle != IntPtr.Zero) { if (!type_map.ContainsKey(type.Handle)) { type_map [type.Handle] = type; } return; } /*FIXME try to guess the name of the missing library - quite trivial for monotouch.dll*/ // types decorated with [Model] attribute are not registered (see registrar.cs and regression from #769) if (type.IsWrapper && !type.IsModel) { if (!IsSimulatorOrDesktop) { // This can happen when Apple introduces new types and puts them as base types for already // existing types. We can't throw any exceptions in that case, since the derived class // can still be used in older iOS versions. // Hardcode these types to ignore any loading errors. // We could also look at the AvailabilityAttribute, but it would require us // to not link it away anymore like we currently do. #if !COREBUILD && !MONOMAC && !WATCH var major = -1; switch (type.Name) { case "PKObject": case "CBAttribute": case "CBPeer": major = 8; break; case "GKGameCenterViewController": major = 6; break; case "CBManager": case "GKBasePlayer": major = 10; break; } if ((major > 0) && !UIDevice.CurrentDevice.CheckSystemVersion(major, 0)) { return; } #endif // a missing [Model] attribute will cause this error on devices (e.g. bug #4864) throw ErrorHelper.CreateError(8005, "Wrapper type '{0}' is missing its native ObjectiveC class '{1}'.", type.Type.FullName, type.Name); } else { /*On simulator this is a common issue since we eagerly register all types. This is an issue with unlinked * monotouch.dll since we don't link all frameworks most of the time. */ return; } } if (type.IsFakeProtocol) { return; } var methods = new Dictionary <IntPtr, MethodDescription> (Runtime.IntPtrEqualityComparer); var super = type.SuperType; type.Handle = Class.objc_allocateClassPair(super.Handle, type.ExportedName, IntPtr.Zero); if (type.Properties != null) { foreach (var property in type.Properties) { int count; var props = GetPropertyAttributes(property, out count, false); Class.class_addProperty(type.Handle, property.Selector, props, count); } } if (type.Fields != null) { foreach (var field in type.Fields.Values) { Class.class_addIvar(type.Handle, field.Name, new IntPtr(field.Size), field.Alignment, field.FieldType); } } if (type.Methods != null) { foreach (var method in type.Methods) { RegisterMethod(method); } } if (type.Protocols != null) { foreach (var protocol in type.Protocols) { Class.class_addProtocol(type.Handle, protocol.Handle); } } Class.objc_registerClassPair(type.Handle); type_map [type.Handle] = type; AddCustomType(type.Type); method_map [type.Type] = methods; Trace(" [DYNAMIC CLASS] Registered the class {0} for {1}", type.ExportedName, type.Type.FullName); }
protected override void OnRegisterProtocol(ObjCType type) { var protocol = Protocol.objc_getProtocol(type.ProtocolName); if (protocol != IntPtr.Zero) { type.Handle = protocol; if (!type_map.ContainsKey(protocol)) { type_map [protocol] = type; } return; } protocol = Protocol.objc_allocateProtocol(type.ProtocolName); if (type.Protocols != null) { foreach (var proto in type.Protocols) { if (proto.ProtocolName == "JSExport") { #if MONOMAC const string msg = "Detected a protocol ({0}) inheriting from the JSExport protocol while using the dynamic registrar. It is not possible to export protocols to JavaScriptCore dynamically; the static registrar must be used (add '--registrar:static' to the additional mmp arguments in the project's Mac Build options to select the static registrar)."; #else const string msg = "Detected a protocol ({0}) inheriting from the JSExport protocol while using the dynamic registrar. It is not possible to export protocols to JavaScriptCore dynamically; the static registrar must be used (add '--registrar:static' to the additional mtouch arguments in the project's iOS Build options to select the static registrar)."; #endif ErrorHelper.Warning(4147, msg, GetTypeFullName(type.Type)); } Protocol.protocol_addProtocol(protocol, proto.Handle); } } if (type.Properties != null) { foreach (var property in type.Properties) { int count; var props = GetPropertyAttributes(property, out count, true); // Only required instance properties are added (the rest of the logic is commented out in the public source at least, // see file objc4-647/runtime/objc-runtime-old.mm in Apple's open source code). Still add all properties in case Apple // implements their missing bits. Protocol.protocol_addProperty(protocol, property.Selector, props, count, !property.IsOptional, !property.IsStatic); // The properties need to be added as methods as well. var propertyType = ToSignature(property.PropertyType, property, false); Protocol.protocol_addMethodDescription(protocol, Selector.GetHandle(property.GetterSelector), propertyType + "@:", !property.IsOptional, !property.IsStatic); if (!property.IsReadOnly) { Protocol.protocol_addMethodDescription(protocol, Selector.GetHandle(property.SetterSelector), "v@:" + propertyType, !property.IsOptional, !property.IsStatic); } } } if (type.Methods != null) { foreach (var method in type.Methods) { Protocol.protocol_addMethodDescription(protocol, Selector.GetHandle(method.Selector), method.Signature, !method.IsOptional, !method.IsStatic); } } Protocol.objc_registerProtocol(protocol); type_map [protocol] = type; Trace(" [DYNAMIC PROTOCOL] Registered the protocol {0} for {1}", type.ProtocolName, type.Type.FullName); }
protected override void OnRegisterType(ObjCType type) { type.Handle = Class.GetHandle(type.ExportedName); if (type.Handle != IntPtr.Zero) { if (!type_map.ContainsKey(type.Handle)) { type_map [type.Handle] = type; } return; } /*FIXME try to guess the name of the missing library - quite trivial for monotouch.dll*/ // types decorated with [Model] attribute are not registered (see registrar.cs and regression from #769) if (type.IsWrapper && !type.IsModel) { // This is a common issue if we use the dynamic registrar, since we eagerly register all types. return; } if (type.IsFakeProtocol) { return; } var super = type.SuperType; type.Handle = Class.objc_allocateClassPair(super.Handle, type.ExportedName, IntPtr.Zero); if (type.Properties != null) { foreach (var property in type.Properties) { int count; var props = GetPropertyAttributes(property, out count, false); Class.class_addProperty(type.Handle, property.Selector, props, count); } } if (type.Fields != null) { foreach (var field in type.Fields.Values) { Class.class_addIvar(type.Handle, field.Name, new IntPtr(field.Size), field.Alignment, field.FieldType); } } if (type.Methods != null) { foreach (var method in type.Methods) { RegisterMethod(method); } } if (type.Protocols != null) { foreach (var protocol in type.Protocols) { Class.class_addProtocol(type.Handle, protocol.Handle); } } Class.objc_registerClassPair(type.Handle); type_map [type.Handle] = type; AddCustomType(type.Type); Trace(" [DYNAMIC CLASS] Registered the class {0} for {1}", type.ExportedName, type.Type.FullName); }
void CheckNamespace(ObjCType objctype, List<Exception> exceptions) { CheckNamespace (objctype.Type, exceptions); }
static bool IsMetalType(ObjCType type) { var ns = type.Type.Namespace; if (!IsDualBuild) ns = ns.Substring (CompatNamespace.Length + 1); switch (ns) { case "Metal": case "MetalKit": case "MetalPerformanceShaders": return true; default: return false; } }