Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typed Record: Add parameterless constructor #1002

Merged
merged 2 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Generation/Generator/Model/TypedRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,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)
{
var prefix = $"{Type.GetName(record)}Array";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ public void Initialize(ParameterToNativeData parameter, IEnumerable<ParameterToN
break;
case GirModel.Direction.InOut:
throw new Exception("PointerAlias: InOut not yet implemented");
break;
case GirModel.Direction.Out:
throw new Exception("PointerAlias: Out not yet implemented");
break;
}
}

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();
}
}
Loading