Fix formatting

This commit is contained in:
Marc Hernandez 2024-04-28 20:05:36 -07:00
parent c18c106b72
commit f965662031

View File

@ -31,7 +31,7 @@ static public class refl
} }
} }
public class PredEnumerator<T>: PredEnumerator, IEnumerator<T> public class PredEnumerator<T> : PredEnumerator, IEnumerator<T>
{ {
public T Current => m_en.Current; public T Current => m_en.Current;
@ -106,7 +106,7 @@ static public class refl
} }
public class PredEnumerable<T>: IEnumerable<T> public class PredEnumerable<T> : IEnumerable<T>
{ {
public PredEnumerable( PredEnumerator<T> en ) public PredEnumerable( PredEnumerator<T> en )
{ {
@ -127,7 +127,27 @@ static public class refl
} }
public static string PrettyName( FieldInfo fi )
{
var name = fi.Name;
if( name[0] != '<' )
return name;
var gtIndex = name.IndexOf( '>' );
name = name.Substring( 1, gtIndex - 1 );
return name;
}
public static void GetAllFields( Type t, List<FieldInfo> list ) public static void GetAllFields( Type t, List<FieldInfo> list )
{
GetAllFieldsRecursive( t, true, list );
}
public static void GetAllFieldsRecursive( Type t, bool recurse, List<FieldInfo> list )
{ {
var fieldArr = t.GetFields( var fieldArr = t.GetFields(
BindingFlags.DeclaredOnly | BindingFlags.DeclaredOnly |
@ -139,11 +159,34 @@ static public class refl
list.AddRange( new PredEnumerable<FieldInfo>( en ) ); list.AddRange( new PredEnumerable<FieldInfo>( en ) );
if( t.BaseType != null && t.BaseType != typeof( object ) ) if( recurse && t.BaseType != null && t.BaseType != typeof( object ) )
{ {
GetAllFields( t.BaseType, list ); GetAllFields( t.BaseType, list );
} }
} }
public static void GetAllFieldsUntil( Type t, Type tooFar, List<FieldInfo> list )
{
var fieldArr = t.GetFields(
BindingFlags.DeclaredOnly |
BindingFlags.NonPublic |
BindingFlags.Public |
BindingFlags.Instance );
var en = PredEnumerator.Create<FieldInfo>( fieldArr.AsEnumerable<FieldInfo>(), fa => fa.GetCustomAttribute( typeof( NonSerializedAttribute ) ) == null );
list.AddRange( new PredEnumerable<FieldInfo>( en ) );
if( t.BaseType != null && t.BaseType != tooFar )
{
GetAllFields( t.BaseType, list );
}
}
public static ImmutableList<FieldInfo> GetAllFields<T>()
{
return GetAllFields( typeof( T ) );
}
public static ImmutableList<FieldInfo> GetAllFields( Type t ) public static ImmutableList<FieldInfo> GetAllFields( Type t )