private static void DoAddMethod(string name, MethodInfo info, string selName, IntPtr klass, Class superClass) { ManagedImp mimp = null; int result = 0; Selector selector = new Selector(selName); try { string encoding = DoGetEncoding(info); Managed method = new Managed(info, encoding); mimp = method.Call; if (info.IsStatic) { klass = object_getClass(klass); } IntPtr cif = DoCreateCif(info); result = AddMethod(superClass, klass, (IntPtr)selector, encoding, mimp, cif); } catch (Exception e) { throw new ArgumentException(string.Format("Couldn't register {0}::{1}. {2}", name, selector.Name, e.Message)); } if (result != 0) { if (result == 0xADDF) { throw new ArgumentException(string.Format("Couldn't add {0}::{1}. Is the method already defined?", name, selector.Name)); } else { throw new ArgumentException(string.Format("Couldn't create a closure for {0}::{1} ({2})", name, selector.Name, result)); } } ms_imps.Add(mimp); }
private extern static int AddMethod(IntPtr superClass, IntPtr klass, IntPtr selector, string sig, ManagedImp imp, IntPtr cif);