mirror of
				https://github.com/nsnail/spectre.console.git
				synced 2025-11-04 10:35:27 +08:00 
			
		
		
		
	Refactor enum value retrieval to use EnumUtils for better compatibility with NetStandard 2.0 and AOT
This commit is contained in:
		
				
					committed by
					
						
						Patrik Svensson
					
				
			
			
				
	
			
			
			
						parent
						
							4802751357
						
					
				
				
					commit
					10773a5625
				
			@@ -54,8 +54,7 @@ internal static class DecorationTable
 | 
				
			|||||||
    {
 | 
					    {
 | 
				
			||||||
        var result = new List<string>();
 | 
					        var result = new List<string>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Enum.GetValues(typeof(Decoration))
 | 
					        EnumUtils.GetValues<Decoration>()
 | 
				
			||||||
            .Cast<Decoration>()
 | 
					 | 
				
			||||||
            .Where(flag => (decoration & flag) != 0)
 | 
					            .Where(flag => (decoration & flag) != 0)
 | 
				
			||||||
            .ForEach(flag =>
 | 
					            .ForEach(flag =>
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -140,7 +140,7 @@ internal struct FileSize
 | 
				
			|||||||
            bytes *= 8;
 | 
					            bytes *= 8;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        foreach (var prefix in (FileSizePrefix[])Enum.GetValues(typeof(FileSizePrefix)))
 | 
					        foreach (var prefix in EnumUtils.GetValues<FileSizePrefix>())
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            // Trying to find the largest unit, that the number of bytes can fit under. Ex. 40kb < 1mb
 | 
					            // Trying to find the largest unit, that the number of bytes can fit under. Ex. 40kb < 1mb
 | 
				
			||||||
            if (bytes < Math.Pow((int)_prefixBase, (int)prefix + 1))
 | 
					            if (bytes < Math.Pow((int)_prefixBase, (int)prefix + 1))
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										15
									
								
								src/Spectre.Console/Internal/Polyfill/EnumHelpers.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								src/Spectre.Console/Internal/Polyfill/EnumHelpers.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,15 @@
 | 
				
			|||||||
 | 
					namespace Spectre.Console;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					internal static class EnumUtils
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    public static T[] GetValues<T>()
 | 
				
			||||||
 | 
					        where T : struct, Enum
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        return
 | 
				
			||||||
 | 
					#if NET6_0_OR_GREATER
 | 
				
			||||||
 | 
					        Enum.GetValues<T>();
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					            (T[])Enum.GetValues(typeof(T));
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user