ret = n + " ";
if (IsDelegateType(type.ToString())) {
- ret += id + " = new " + n +"(port);\n";
+ ret += id + " = new " + n +"(port, new WeakReference(b));\n";
ret += "CallbackBase.";
} else {
ret += id + " = new " + n +"();\n";
"{\n" \
"}\n" \
"\n" \
- "internal $$(IntPtr port) : base((int)DelegateId.$$)\n" \
+ "internal $$(IntPtr port, WeakReference service) : base((int)DelegateId.$$)\n" \
"{\n" \
" _port = port;\n" \
+ " _service = service;\n" \
"}\n";
GenTemplate(AddIndent(TAB_SIZE * 4, ctor), stream,
stream << NLine(1);
stream << Tab(4) << "private IntPtr _port;" << NLine(1);
+ stream << Tab(4) << "private WeakReference _service;" << NLine(1);
stream << Tab(4) << "public delegate void Callback(";
GenParameters(stream, decl.GetParameters());
stream << ");" << NLine(1);
void CsGeneratorBase::GenInvokeMethod(std::ofstream& stream,
const Declaration& decl) {
const char* pre =
- "if (_port == IntPtr.Zero)\n" \
+ "if (_port == IntPtr.Zero || _service == null)\n" \
" throw new InvalidOperationException(\"Not connected!\");\n" \
+ "if (!_service.IsAlive)\n" \
+ " throw new InvalidOperationException(\"Invalid delegate object!\");\n" \
"\n" \
"Interop.LibRPCPort.Parcel.Create(out IntPtr p);\n" \
"Interop.LibRPCPort.Parcel.WriteInt32(p, (int)MethodId.Callback);\n" \