]> O.S.I.I.S - jp/crow.git/commitdiff
try FastEnum
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Wed, 13 May 2020 20:23:56 +0000 (22:23 +0200)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Wed, 13 May 2020 20:23:56 +0000 (22:23 +0200)
Crow/Crow.csproj
Crow/src/Colors.cs
Crow/src/Font.cs
Crow/src/IML/CompilerServices.cs
Crow/src/Widgets/DockStack.cs
PerfTests/Program.cs

index bc5594aa34516acbe779161622f6d24512dab801..94977dec0f3be8f30c039b79fc8540c442bff144 100644 (file)
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="utf-8"?>
 <Project Sdk="Microsoft.NET.Sdk">
        <PropertyGroup>
-               <TargetFramework>netstandard2.0</TargetFramework>
+               <TargetFrameworks>netstandard2.0</TargetFrameworks>
                
                <AssemblyVersion>$(CrowVersion)</AssemblyVersion>
                <ReleaseVersion>$(CrowVersion)</ReleaseVersion>
@@ -40,6 +40,7 @@
                <PackageReference Include="System.Reflection.Emit.Lightweight" Version="4.6.0" />
                <!--<PackageReference Include="glfw-sharp" Version="0.2.0" />-->
 <!--           <PackageReference Include="glfw-sharp" Version="0.2.5" />-->
+               <PackageReference Include="FastEnum" Version="1.5.3" />
        </ItemGroup>
        <PropertyGroup Condition=" '$(CrowStbSharp)' == 'true'">
                <DefineConstants>$(DefineConstants);STB_SHARP</DefineConstants>
index 763aed07b5a6bc3e5bfd22de9832488b960efcf8..d33db1797bc106e6668897f43f9478ed75e1bc0f 100644 (file)
@@ -5,6 +5,7 @@
 using System;
 using System.Collections.Generic;
 using System.Linq;
+using FastEnumUtility;
 
 namespace Crow
 {
@@ -327,7 +328,7 @@ namespace Crow
                        => value.GetHashCode ();
 
                public override string ToString()
-                       => Enum.IsDefined (typeof (Colors), value) ? ((Colors)value).ToString () : HtmlCode;
+                       => FastEnum.IsDefined<Colors> (value) ? FastEnum.GetName((Colors)value) : HtmlCode;
                        
                public static Color FromIml (string iml)
                {
@@ -343,7 +344,7 @@ namespace Crow
                        => (string.IsNullOrEmpty (s)) ? new Color (Colors.White) :
                                (s.StartsWith ("#", StringComparison.Ordinal)) ? new Color (UInt32.Parse (s.Substring (1), System.Globalization.NumberStyles.HexNumber)) :
                                (char.IsDigit(s[0])) ? FromIml (s) :
-                               (Enum.TryParse<Colors> (s, out Colors cc)) ? new Color(cc) :
+                               (FastEnum.TryParse<Colors> (s, out Colors cc)) ? new Color(cc) :
                                throw new Exception ("Unknown color name: " + s);
 
 
index 06df4a88ae6f78d1367c7cf5668796fbab3eb538..4bf5fab3f7f273edbdd56831b487312e38fb6974 100644 (file)
@@ -26,6 +26,7 @@
 
 using System;
 using Crow.Cairo;
+using FastEnumUtility;
 
 namespace Crow
 {
@@ -102,7 +103,7 @@ namespace Crow
                                f.Name = n [0];
 
                                if (n.Length > 1)
-                                       f.Style = (FontStyle)Enum.Parse (typeof(FontStyle), n[n.Length-1], true);
+                                       f.Style = FastEnum.Parse<FontStyle> (n[n.Length-1], true);
                        }
 
                        return f;
index 847292eb7c0bbb73e81fa47bbd3f6ff9c2bc0d43..ffd5f34cd8097cd3bde37b8d4abde2c5f0d693c3 100644 (file)
@@ -12,6 +12,7 @@ using System.Runtime.CompilerServices;
 using System.Xml;
 using Crow.IML;
 using System.Text;
+using FastEnumUtility;
 
 namespace Crow.IML
 {
index 0e8c980238b6602f927307f69c4193e90bbe9477..50e87b1ce3b76d155d1bb597864076e04d7a0245 100644 (file)
@@ -28,6 +28,7 @@ using Crow.IML;
 using System.Linq;
 using System.Text;
 using System.IO;
+using FastEnumUtility;
 
 namespace Crow
 {
@@ -389,7 +390,7 @@ namespace Crow
                                ClearChildren ();
                                stretchedChild = null;
                                int i = 0;
-                               Orientation = (Orientation)Enum.Parse (typeof(Orientation), getConfAttrib (conf, ref i));
+                               Orientation = FastEnum.Parse<Orientation> (getConfAttrib (conf, ref i));
                                importConfig (conf, ref i, dataSource);
                        }
                }
@@ -415,7 +416,7 @@ namespace Crow
                                        dw.Name = wName;
                                        dw.Width = Measure.Parse (getConfAttrib (conf, ref i));
                                        dw.Height = Measure.Parse (getConfAttrib (conf, ref i));
-                                       dw.DockingPosition = (Alignment)Enum.Parse (typeof(Alignment), getConfAttrib (conf, ref i));
+                                       dw.DockingPosition = FastEnum.Parse<Alignment> (getConfAttrib (conf, ref i));
                                        dw.savedSlot = Rectangle.Parse (getConfAttrib (conf, ref i));
                                        dw.wasResizable = Boolean.Parse (getConfAttrib (conf, ref i));
 
@@ -428,7 +429,7 @@ namespace Crow
                                        DockStack ds = new DockStack (IFace);
                                        ds.Width = Measure.Parse (getConfAttrib (conf, ref i));
                                        ds.Height = Measure.Parse (getConfAttrib (conf, ref i));
-                                       ds.Orientation = (Orientation)Enum.Parse (typeof(Orientation), getConfAttrib (conf, ref i));
+                                       ds.Orientation = FastEnum.Parse<Orientation> (getConfAttrib (conf, ref i));
 
                                        this.AddChild (ds);
 
index e97014dff32cda6b4a32ec57d70e9997aac28046..8b83a592738d0ecf6cbc76d95c6a5148eddad1fa 100644 (file)
@@ -50,7 +50,7 @@ namespace PerfTests
 
                void testDir (string dirPath, int level = 0)
                {
-                       Console.WriteLine ($"{new string (' ', level * 4)}-{dirPath}");
+                       Console.WriteLine ($"{new string (' ', level * 4)}- {dirPath}");
                        level++;
 
                        foreach (string d in Directory.GetDirectories (dirPath)) 
@@ -59,10 +59,10 @@ namespace PerfTests
                        foreach (string f in Directory.GetFiles (dirPath)) {
                                try {
                                        long mean = Test (f, out long min, out long max);
-                                       Console.WriteLine ($"{new string (' ', level * 4)}{ Path.GetFileName (f),-30}: {min,5} |{mean,5} |{max,5}");
+                                       Console.WriteLine ($"{new string (' ', level * 4)}{ Path.GetFileName (f),-30}|{min,5}|{mean,5}|{max,5}");
                                } catch (Exception ex) {
                                        Console.ForegroundColor = ConsoleColor.Red;
-                                       Console.WriteLine ($"{ex.Message}");
+                                       Console.WriteLine ($"{ex.Message}");
                                        Console.ResetColor ();
                                }
                        }