Skip to content

Commit 2d27308

Browse files
committed
improve colormap reflection
1 parent 32225cd commit 2d27308

1 file changed

Lines changed: 4 additions & 15 deletions

File tree

src/Spectrogram/Colormap.cs

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.ComponentModel;
42
using System.Drawing;
53
using System.Linq;
6-
using System.Text;
74

85
namespace Spectrogram
96
{
@@ -34,18 +31,10 @@ public override string ToString()
3431
return $"Colormap {Name}";
3532
}
3633

37-
public static Colormap[] GetColormaps()
38-
{
39-
IColormap[] ics = AppDomain.CurrentDomain.GetAssemblies()
40-
.SelectMany(s => s.GetTypes())
41-
.Where(p => p.IsInterface == false)
42-
.Where(p => p.ToString().StartsWith("Spectrogram.Colormaps."))
43-
.Select(x => x.ToString())
44-
.Select(path => (IColormap)Activator.CreateInstance(Type.GetType(path)))
45-
.ToArray();
46-
47-
return ics.Select(x => new Colormap(x)).ToArray();
48-
}
34+
public static Colormap[] GetColormaps() =>
35+
typeof(Colormap).GetProperties()
36+
.Select(x => (Colormap)x.GetValue(x.Name))
37+
.ToArray();
4938

5039
public static string[] GetColormapNames()
5140
{

0 commit comments

Comments
 (0)