+
Skip to content

GObject.Type: Add IsFundamental method #1123

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

Merged
merged 2 commits into from
Sep 22, 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
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();
}
}
Loading
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载