2022-02-13 02:41:16 +01:00
|
|
|
using System.Collections;
|
|
|
|
|
2022-02-12 02:29:25 +01:00
|
|
|
namespace meowlang.parser;
|
|
|
|
|
2022-02-13 02:41:16 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|