From a1ceda7e8718a781557b406a45fb16b36bcb9aa1 Mon Sep 17 00:00:00 2001 From: Simon Bernard Date: Mon, 29 Jun 2026 15:18:55 +0200 Subject: [PATCH 1/2] Fix: Interfaces should have their interfaces as basetype --- .../SAssemblyCatalog/Misc/InterfaceDemo.cs | 22 ++++++++++ .../TAssemblyCatalog/BaseTypeTests.cs | 41 +++++++++++++++++++ PCTTools/AssemblyCatalog.cs | 18 ++++++-- 3 files changed, 77 insertions(+), 4 deletions(-) create mode 100644 PCTTools.Sample/SAssemblyCatalog/Misc/InterfaceDemo.cs create mode 100644 PCTTools.Tests/TAssemblyCatalog/BaseTypeTests.cs diff --git a/PCTTools.Sample/SAssemblyCatalog/Misc/InterfaceDemo.cs b/PCTTools.Sample/SAssemblyCatalog/Misc/InterfaceDemo.cs new file mode 100644 index 0000000..e72a3a7 --- /dev/null +++ b/PCTTools.Sample/SAssemblyCatalog/Misc/InterfaceDemo.cs @@ -0,0 +1,22 @@ +namespace PCTTools.Sample.SAssemblyCatalog.Misc +{ + public interface IParentInterface + { + string ParentProp { get; set; } + } + + public interface IParentBInterface + { + string ParentProp { get; set; } + } + + public interface IChildInterface : IParentInterface + { + string ChildProp { get; set; } + } + + public interface IChildMultiParentInterface : IParentInterface, IParentBInterface + { + string ChildProp { get; set; } + } +} \ No newline at end of file diff --git a/PCTTools.Tests/TAssemblyCatalog/BaseTypeTests.cs b/PCTTools.Tests/TAssemblyCatalog/BaseTypeTests.cs new file mode 100644 index 0000000..a0cc834 --- /dev/null +++ b/PCTTools.Tests/TAssemblyCatalog/BaseTypeTests.cs @@ -0,0 +1,41 @@ +using NUnit.Framework; +using PCTTools.Sample.SAssemblyCatalog.Misc; + +namespace PCTTools.Tests.TAssemblyCatalog +{ + + [TestFixture()] + public class BaseTypeTests + { + [Test()] + public void InterfaceBaseTypesTest() + { + var pct = new AssemblyCatalog(); + + pct.GenerateDocumentationFromAssembly(typeof(IParentInterface).Assembly); + Assert.That(pct.HasError, Is.False); + + var childMultiParentInterface = pct.TypeDocumentations.First(x => x.IsInterface && x.ShortName == nameof(IChildMultiParentInterface)); + Assert.That(childMultiParentInterface.BaseTypes.Count, Is.EqualTo(2), $"{nameof(IChildMultiParentInterface)} doit avoir 2 parents"); + Assert.That(childMultiParentInterface.BaseTypes, Does.Contain(typeof(IParentInterface).FullName)); + Assert.That(childMultiParentInterface.BaseTypes, Does.Contain(typeof(IParentBInterface).FullName)); + + var childParentInterface = pct.TypeDocumentations.First(x => x.IsInterface && x.ShortName == nameof(IChildInterface)); + Assert.That(childParentInterface.BaseTypes.Count, Is.EqualTo(1), $"{nameof(IChildInterface)} doit avoir 1 parent"); + Assert.That(childParentInterface.BaseTypes, Does.Contain(typeof(IParentInterface).FullName)); + + var doctype = pct.TypeDocumentations.First(t => t.Name.Equals( + typeof(IParentInterface).FullName)); + + Assert.That(doctype.IsInterface, Is.EqualTo(true), "IParentInterface doit être une interface"); + Assert.That(doctype.BaseTypes, Is.Not.Null, "BaseTypes ne doit pas être null"); + Assert.That(doctype.BaseTypes, Is.Empty, "Une interface sans parent ne doit avoir aucun BaseType"); + + doctype = pct.TypeDocumentations.First(t => t.Name.Equals( + typeof(IChildInterface).FullName)); + + Assert.That(doctype.IsInterface, Is.EqualTo(true), "IChildInterface doit être une interface"); + Assert.That(doctype.BaseTypes, Is.Not.Null, "BaseTypes ne doit pas être null"); + } + } +} \ No newline at end of file diff --git a/PCTTools/AssemblyCatalog.cs b/PCTTools/AssemblyCatalog.cs index df971d7..6f3e565 100644 --- a/PCTTools/AssemblyCatalog.cs +++ b/PCTTools/AssemblyCatalog.cs @@ -411,12 +411,22 @@ internal List GetBaseTypes(Type type) { var baseTypes = new List(); - var baseType = type.BaseType; - while (baseType != null) + if (type.IsInterface) { - baseTypes.Add(baseType.FullName); + foreach (var iface in type.GetInterfaces()) + { + baseTypes.Add(iface.FullName); + } + } + else + { + var baseType = type.BaseType; + while (baseType != null) + { + baseTypes.Add(baseType.FullName); - baseType = baseType.BaseType; + baseType = baseType.BaseType; + } } return baseTypes; } From 4417b75970fe72400c6a12ffb282f3cc651edd5b Mon Sep 17 00:00:00 2001 From: Simon Bernard Date: Mon, 29 Jun 2026 15:32:14 +0200 Subject: [PATCH 2/2] fix english --- PCTTools.Tests/TAssemblyCatalog/BaseTypeTests.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/PCTTools.Tests/TAssemblyCatalog/BaseTypeTests.cs b/PCTTools.Tests/TAssemblyCatalog/BaseTypeTests.cs index a0cc834..64dac43 100644 --- a/PCTTools.Tests/TAssemblyCatalog/BaseTypeTests.cs +++ b/PCTTools.Tests/TAssemblyCatalog/BaseTypeTests.cs @@ -16,26 +16,26 @@ public void InterfaceBaseTypesTest() Assert.That(pct.HasError, Is.False); var childMultiParentInterface = pct.TypeDocumentations.First(x => x.IsInterface && x.ShortName == nameof(IChildMultiParentInterface)); - Assert.That(childMultiParentInterface.BaseTypes.Count, Is.EqualTo(2), $"{nameof(IChildMultiParentInterface)} doit avoir 2 parents"); + Assert.That(childMultiParentInterface.BaseTypes.Count, Is.EqualTo(2), $"{nameof(IChildMultiParentInterface)} should have 2 parents"); Assert.That(childMultiParentInterface.BaseTypes, Does.Contain(typeof(IParentInterface).FullName)); Assert.That(childMultiParentInterface.BaseTypes, Does.Contain(typeof(IParentBInterface).FullName)); var childParentInterface = pct.TypeDocumentations.First(x => x.IsInterface && x.ShortName == nameof(IChildInterface)); - Assert.That(childParentInterface.BaseTypes.Count, Is.EqualTo(1), $"{nameof(IChildInterface)} doit avoir 1 parent"); + Assert.That(childParentInterface.BaseTypes.Count, Is.EqualTo(1), $"{nameof(IChildInterface)} should have 1 parent"); Assert.That(childParentInterface.BaseTypes, Does.Contain(typeof(IParentInterface).FullName)); var doctype = pct.TypeDocumentations.First(t => t.Name.Equals( typeof(IParentInterface).FullName)); - Assert.That(doctype.IsInterface, Is.EqualTo(true), "IParentInterface doit être une interface"); - Assert.That(doctype.BaseTypes, Is.Not.Null, "BaseTypes ne doit pas être null"); - Assert.That(doctype.BaseTypes, Is.Empty, "Une interface sans parent ne doit avoir aucun BaseType"); + Assert.That(doctype.IsInterface, Is.EqualTo(true), "IParentInterface should be an interface"); + Assert.That(doctype.BaseTypes, Is.Not.Null, "BaseTypes should not be null"); + Assert.That(doctype.BaseTypes, Is.Empty, "An interface with no parent should have no BaseTypes"); doctype = pct.TypeDocumentations.First(t => t.Name.Equals( typeof(IChildInterface).FullName)); - Assert.That(doctype.IsInterface, Is.EqualTo(true), "IChildInterface doit être une interface"); - Assert.That(doctype.BaseTypes, Is.Not.Null, "BaseTypes ne doit pas être null"); + Assert.That(doctype.IsInterface, Is.EqualTo(true), "IChildInterface should be an interface"); + Assert.That(doctype.BaseTypes, Is.Not.Null, "BaseTypes should not be null"); } } } \ No newline at end of file