Skip to content

Commit 92f774a

Browse files
author
Fabio Anderegg
authored
__CreateInstance: return C# null when native is null (#1698)
1 parent eab7a0c commit 92f774a

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/Generator/Generators/CSharp/CSharpSources.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2384,6 +2384,13 @@ private void GenerateNativeConstructor(Class @class)
23842384
@class.NeedsBase && !@class.BaseClass.IsInterface ? "new " : string.Empty,
23852385
printedClass, Helpers.CreateInstanceIdentifier, TypePrinter.IntPtrType);
23862386
WriteOpenBraceAndIndent();
2387+
2388+
if (@class.IsRefType)
2389+
{
2390+
WriteLine($"if (native == {TypePrinter.IntPtrType}.Zero)");
2391+
WriteLineIndent("return null;");
2392+
}
2393+
23872394
var suffix = @class.IsAbstract ? "Internal" : string.Empty;
23882395
var ctorCall = $"{printedClass.Type}{suffix}{printedClass.NameSuffix}";
23892396
WriteLine("return new {0}(native.ToPointer(), skipVTables);", ctorCall);

0 commit comments

Comments
 (0)