public virtual void BeginHeaders() { headers.WriteLine(); headers.WriteLine($"/** Class {Name}"); headers.WriteLine($" * Corresponding .NET Qualified Name: `{AssemblyQualifiedName}`"); headers.WriteLine(" */"); headers.Write($"@interface {Name} : {BaseTypeName}"); var pcount = Protocols.Count; if (pcount > 0) { headers.Write(" <"); for (int i = 0; i < pcount; i++) { if (i > 0) { headers.Write(", "); } headers.Write(Protocols [i]); } headers.Write(">"); } headers.WriteLine(" {"); if (!IsStatic && !IsBaseTypeBound) { headers.Indent++; headers.WriteLine("// This field is not meant to be accessed from user code"); headers.WriteLine("@public MonoEmbedObject* _object;"); headers.Indent--; } headers.WriteLine("}"); headers.WriteLine(); }
public void WriteInvoke(string args) { implementation.WriteLine("MonoObject* __exception = nil;"); var instance = "nil"; if (!IsStatic) { if (!IsConstructor) { implementation.WriteLine($"MonoObject* __instance = mono_gchandle_get_target (_object->_handle);"); } if (IsValueType) { implementation.WriteLine($"void* __unboxed = mono_object_unbox (__instance);"); instance = "__unboxed"; } else { instance = "__instance"; } } var method = "__method"; if (IsVirtual) { implementation.WriteLine($"MonoMethod* __virtual_method = mono_object_get_virtual_method ((MonoObject *){instance}, __method);"); method = "__virtual_method"; } if (!IsConstructor && (ReturnType != "void")) { implementation.Write("MonoObject* __result = "); } implementation.WriteLine($"mono_runtime_invoke ({method}, {instance}, {args}, &__exception);"); implementation.WriteLine("if (__exception) {"); implementation.Indent++; if (IgnoreException) { // TODO: Apple often do NSLog (or asserts but they are more brutal) and returning nil is allowed (and common) implementation.WriteLine("NSLog (@\"%@\", mono_embeddinator_get_nsstring (mono_object_to_string (__exception, nil)));"); implementation.WriteLine("return nil;"); } else { implementation.WriteLine("mono_embeddinator_throw_exception (__exception);"); } implementation.Indent--; implementation.WriteLine("}"); }
void WriteSignature(SourceWriter writer) { writer.Write(IsStatic && !IsExtension ? '+' : '-'); writer.Write($" ({ReturnType}){ObjCSignature}"); }