aboutsummaryrefslogtreecommitdiffstatsci
diff options
context:
space:
mode:
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>2020-05-13 22:23:56 +0200
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>2020-05-13 22:23:56 +0200
commit31125f2b7fc7517a324e90058bce2f2cec063f7c (patch)
tree8c525d44ffa349fab320b15222d2d573d42e72c5
parent6428afe998093c656a1e76a8cbebf96258c60a50 (diff)
try FastEnum
-rw-r--r--Crow/Crow.csproj3
-rw-r--r--Crow/src/Colors.cs5
-rw-r--r--Crow/src/Font.cs3
-rw-r--r--Crow/src/IML/CompilerServices.cs1
-rw-r--r--Crow/src/Widgets/DockStack.cs7
-rw-r--r--PerfTests/Program.cs6
6 files changed, 15 insertions, 10 deletions
diff --git a/Crow/Crow.csproj b/Crow/Crow.csproj
index bc5594aa..94977dec 100644
--- a/Crow/Crow.csproj
+++ b/Crow/Crow.csproj
@@ -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>
diff --git a/Crow/src/Colors.cs b/Crow/src/Colors.cs
index 763aed07..d33db179 100644
--- a/Crow/src/Colors.cs
+++ b/Crow/src/Colors.cs
@@ -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);
diff --git a/Crow/src/Font.cs b/Crow/src/Font.cs
index 06df4a88..4bf5fab3 100644
--- a/Crow/src/Font.cs
+++ b/Crow/src/Font.cs
@@ -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;
diff --git a/Crow/src/IML/CompilerServices.cs b/Crow/src/IML/CompilerServices.cs
index 847292eb..ffd5f34c 100644
--- a/Crow/src/IML/CompilerServices.cs
+++ b/Crow/src/IML/CompilerServices.cs
@@ -12,6 +12,7 @@ using System.Runtime.CompilerServices;
using System.Xml;
using Crow.IML;
using System.Text;
+using FastEnumUtility;
namespace Crow.IML
{
diff --git a/Crow/src/Widgets/DockStack.cs b/Crow/src/Widgets/DockStack.cs
index 0e8c9802..50e87b1c 100644
--- a/Crow/src/Widgets/DockStack.cs
+++ b/Crow/src/Widgets/DockStack.cs
@@ -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);
diff --git a/PerfTests/Program.cs b/PerfTests/Program.cs
index e97014df..8b83a592 100644
--- a/PerfTests/Program.cs
+++ b/PerfTests/Program.cs
@@ -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 ();
}
}