using System.Reflection; namespace Syntriax.Engine.Serialization; internal static class Utils { internal static TypeData GetTypeData(this Type type) { IEnumerable eventInfos = type.GetEvents(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public) .OrderBy(ei => ei.Name) .AsEnumerable(); IEnumerable fieldInfos = type.GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public) .Where(fi => !eventInfos.Any(ei => fi.Name.CompareTo(ei.Name) == 0)) .OrderBy(ei => ei.Name) //ei => ei.FieldType.IsPrimitive || ei.FieldType == typeof(string)) // .ThenByDescending(ei => ei.Name) .AsEnumerable(); IEnumerable propertyInfos = type.GetProperties(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public) .Where(pi => pi.SetMethod is not null) .OrderBy(ei => ei.Name)// ei => ei.PropertyType.IsPrimitive || ei.PropertyType == typeof(string)) // .ThenByDescending(ei => ei.Name) .AsEnumerable(); return new TypeData(eventInfos, fieldInfos, propertyInfos); } } internal record struct TypeData(IEnumerable Events, IEnumerable Fields, IEnumerable Properties) { public static implicit operator (IEnumerable events, IEnumerable fields, IEnumerable properties)(TypeData value) => (value.Events, value.Fields, value.Properties); public static implicit operator TypeData((IEnumerable events, IEnumerable fields, IEnumerable properties) value) => new TypeData(value.events, value.fields, value.properties); }