Skip to content

Commit

Permalink
Merge pull request #1123 from gircore/is-fundamental-api
Browse files Browse the repository at this point in the history
GObject.Type: Add IsFundamental method
  • Loading branch information
badcel authored Sep 22, 2024
2 parents de22d73 + 357a6bd commit 5a0ef8b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace {Namespace.GetInternalName(functions.First().Namespace)};
// AUTOGENERATED FILE - DO NOT MODIFY
public partial class Functions
public static partial class Functions
{{
{Functions.Render(functions)}
}}";
Expand Down
10 changes: 10 additions & 0 deletions src/Libs/GObject-2.0/Internal/Functions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,14 @@ public partial class Functions
// why it is defined manually here.
[DllImport(ImportResolver.Library, EntryPoint = "g_strv_get_type")]
internal static extern nuint StrvGetType();

/// <summary>
/// Returns whether the given type is a fundamental type.
/// </summary>
/// <returns>True if the type is fundamental otherwise false.</returns>
public static bool IsFundamental(nuint type)
{
//255 << 2 corresponds to G_TYPE_FUNDAMENTAL_MAX
return type <= (255 << 2);
}
}
13 changes: 13 additions & 0 deletions src/Tests/Libs/GObject-2.0.Tests/Records/TypeTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,17 @@ public void SizeOfTypeIs8()
sizeof(Type).Should().Be(8);
}
}

[TestMethod]
public void FundamentalTypesCanBeDetected()
{
//(255 << 2) => G_TYPE_FUNDAMENTAL_MAX
Internal.Functions.IsFundamental(255 << 2).Should().BeTrue();

//Fundamental types
Internal.Functions.IsFundamental(Object.GetGType().Value).Should().BeTrue();

//Non fundamental types
Internal.Functions.IsFundamental(Binding.GetGType().Value).Should().BeFalse();
}
}

0 comments on commit 5a0ef8b

Please sign in to comment.