d6bdd08002
the typechecker project can collect all the top level types from a file, which is pretty cool I think (except for pointers, those aren't implemented yet...)
30 lines
935 B
C#
30 lines
935 B
C#
using System.Collections;
|
|
|
|
namespace meowlang.parser;
|
|
|
|
public abstract record ModelBase([property: Ignore] Span Span)
|
|
{
|
|
public Dictionary<Guid, object> Metadata { get; } = new();
|
|
|
|
public virtual IEnumerable<ModelBase> GetChildren()
|
|
{
|
|
var properties = GetType().GetProperties();
|
|
foreach (var propertyInfo in properties)
|
|
{
|
|
if (propertyInfo.PropertyType.IsAssignableTo(typeof(ModelBase)))
|
|
{
|
|
if (propertyInfo.GetValue(this) is ModelBase value) yield return value;
|
|
}
|
|
else if (propertyInfo.PropertyType.IsAssignableTo(typeof(IEnumerable)))
|
|
{
|
|
if (propertyInfo.GetValue(this) is IEnumerable<ModelBase> values)
|
|
{
|
|
foreach (var value in values)
|
|
{
|
|
yield return value;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |