Skip to content
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
22 changes: 22 additions & 0 deletions PCTTools.Sample/SAssemblyCatalog/Misc/InterfaceDemo.cs
Original file line number Diff line number Diff line change
@@ -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; }
}
}
41 changes: 41 additions & 0 deletions PCTTools.Tests/TAssemblyCatalog/BaseTypeTests.cs
Original file line number Diff line number Diff line change
@@ -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)} 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)} 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 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 should be an interface");
Assert.That(doctype.BaseTypes, Is.Not.Null, "BaseTypes should not be null");
}
}
}
18 changes: 14 additions & 4 deletions PCTTools/AssemblyCatalog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -411,12 +411,22 @@ internal List<string> GetBaseTypes(Type type)
{
var baseTypes = new List<string>();

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;
}
Expand Down
Loading