forked from CesiumGS/cesium-unity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
InheritanceChainer.cs
39 lines (37 loc) · 1.47 KB
/
InheritanceChainer.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using Microsoft.CodeAnalysis;
namespace Reinterop
{
internal class InheritanceChainer
{
/// <summary>
/// Sets the baseClass and interfaces properties of a given GenerationItem from the appropriate
/// items in the full list of GenerationItems.
/// </summary>
/// <param name="item">The item for which to set the baseClass and interfaces properties.</param>
/// <param name="items">The full list of generation items.</param>
public static void Chain(TypeToGenerate item, Dictionary<ITypeSymbol, TypeToGenerate> items)
{
// This item's immediate base class might not be generated. So walk up the inheritance chain
// until we find one that is.
ITypeSymbol? current = item.Type.BaseType;
while (current != null)
{
TypeToGenerate baseGenerationItem;
if (items.TryGetValue(current, out baseGenerationItem))
{
item.BaseClass = baseGenerationItem;
break;
}
current = current.BaseType;
}
foreach (ITypeSymbol anInterface in item.Type.AllInterfaces)
{
TypeToGenerate interfaceGenerationItem;
if (items.TryGetValue(anInterface, out interfaceGenerationItem))
{
item.Interfaces.Add(interfaceGenerationItem);
}
}
}
}
}