Skip to content

Commit

Permalink
Typed Record: Add parameterless constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
badcel committed Jan 15, 2024
1 parent ce3bceb commit d06e29d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Generation/Generator/Model/TypedRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ public static string GetDataName(GirModel.Record record)

public static string GetFullyQuallifiedDataName(GirModel.Record record)
=> $"{Namespace.GetInternalName(record.Namespace)}.{GetDataName(record)}";

public static string GetFullyQuallifiedManagedHandle(GirModel.Record record)
=> $"{Namespace.GetInternalName(record.Namespace)}.{GetInternalManagedHandle(record)}";

public static string GetInternalArrayHandle(GirModel.Record record)
{
Expand Down
4 changes: 4 additions & 0 deletions src/Generation/Generator/Renderer/Public/TypedRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ public partial class {name}
Initialize();
}}
public {name}() : this({Model.TypedRecord.GetFullyQuallifiedManagedHandle(record)}.Create())
{{
}}
//TODO: This is a workaround constructor as long as we are
//not having https://github.com/gircore/gir.core/issues/397
private {name}(IntPtr ptr, bool ownsHandle) : this(ownsHandle
Expand Down
7 changes: 7 additions & 0 deletions src/Tests/Libs/GirTest-0.1.Tests/TypedRecordTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -367,4 +367,11 @@ public void SupportsPrivateFields()
//Private fields are not rendered in the public API
typeof(TypedRecordTester).GetProperty(nameof(data.CustomIntPrivate)).Should().BeNull();
}

[TestMethod]
public void HasParameterlessConstructor()
{
var instance = new TypedRecordTester();
instance.Should().NotBeNull();
}
}

0 comments on commit d06e29d

Please sign in to comment.