using System.Reflection; namespace Syntriax.Engine.Serialization; internal static class Utils { internal static bool IsEnumerable(this Type type) => typeof(System.Collections.IEnumerable).IsAssignableFrom(type) && type != typeof(string); internal static TypeData GetTypeData(this Type objectType) { // IEnumerable eventInfos = objectType.GetEvents(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public) // .OrderBy(ei => ei.Name) // .ToList(); List fieldInfos = objectType.GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public) .OrderBy(ei => ei.Name) //ei => ei.FieldType.IsPrimitive || ei.FieldType == typeof(string)) // .ThenByDescending(ei => ei.Name) .ToList(); List propertyInfos = objectType.GetProperties(BindingFlags.Instance | 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) .ToList(); propertyInfos.AddRange( objectType.GetProperties(BindingFlags.Instance | BindingFlags.NonPublic) .Where(pi => pi.SetMethod is not null && pi.GetCustomAttribute() is not null) .OrderBy(ei => ei.Name)// ei => ei.PropertyType.IsPrimitive || ei.PropertyType == typeof(string)) // .ThenByDescending(ei => ei.Name) .ToList() ); return new TypeData(fieldInfos, propertyInfos); } } internal record struct TypeData(IEnumerable Fields, IEnumerable Properties) { public static implicit operator (IEnumerable fields, IEnumerable properties)(TypeData value) => (value.Fields, value.Properties); public static implicit operator TypeData((IEnumerable fields, IEnumerable properties) value) => new(value.fields, value.properties); }