Skip to content

Commit

Permalink
Merge pull request #910 from hol430/bug/GenericGObject
Browse files Browse the repository at this point in the history
Fix generic gobject types
  • Loading branch information
badcel authored Jul 28, 2023
2 parents ceef69d + efd0756 commit 38761d5
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/Libs/GObject-2.0/Public/Object.Registration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,14 @@ private Type GetGTypeOrRegister(System.Type type)
private static class FallbackRegistrationStrategy
{
private static string QualifyName(System.Type type)
=> type.FullName?.Replace(".", "") ?? type.Name;
=> type.ToString()
.Replace(".", string.Empty)
.Replace("+", string.Empty)
.Replace("`", string.Empty)
.Replace("[", "_")
.Replace("]", string.Empty)
.Replace(" ", string.Empty)
.Replace(",", "_");

public static void RegisterSubclassRecursive(System.Type type)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace GObject.Tests.Classes;

internal class GenericClass : GObject.Object
{
public GenericClass() : base(true, Array.Empty<GObject.ConstructArgument>())
{
}
}
internal class GenericClass<T> : GObject.Object
{
public GenericClass() : base(true, Array.Empty<GObject.ConstructArgument>())
{
}
}
internal class GenericClass<T1, T2> : GObject.Object
{
public GenericClass() : base(true, Array.Empty<GObject.ConstructArgument>())
{
}
}

[TestClass, TestCategory("UnitTest")]
public class GenericTypeRegistrationTests
{
private class NestedGenericClass<T> : GObject.Object
{
public NestedGenericClass() : base(true, Array.Empty<GObject.ConstructArgument>())
{
}
}

[TestMethod]
public void TestDynamicGenericTypeRegistration()
{
// (Invalid names will cause the test host to crash.)
using (new GenericClass<int, int>()) { };
using (new GenericClass<GenericClass, string>()) { };
using (new GenericClass<GenericClass<string>>()) { };
using (new NestedGenericClass<GenericClass<string>>()) { };
}
}

0 comments on commit 38761d5

Please sign in to comment.