using System.Collections; namespace meowlang.parser; public abstract record ModelBase([property: Ignore] Span Span) { public Dictionary Metadata { get; } = new(); public virtual IEnumerable 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 values) { foreach (var value in values) { yield return value; } } } } } }