Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/ResultFormatter/ResultFormatter.cs @ 17834

Last change on this file since 17834 was 17834, checked in by dpiringe, 3 years ago

#3026

  • added ResultFormatter to add an extra layer of result transformation logic (converting a result value to a string with a defined logic, e.g. MatlabResultFormatter for ISymbolicRegressionSolution)
  • extended the IResultJsonItem with two properties for result formatting
  • added a new control to selected a result formatter for a result value
  • refactored the Runner for the new result formatting process
File size: 1.1 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Threading.Tasks;
6
7namespace HeuristicLab.JsonInterface {
8
9  /// <summary>
10  /// Base Class for ResultFormatter
11  /// </summary>
12  public abstract class ResultFormatter : IResultFormatter {
13    public abstract int Priority { get; }
14
15    public abstract bool CanFormatType(Type t);
16    public abstract string Format(object o);
17
18    /// <summary>
19    /// static property to get all existing result formatters
20    /// </summary>
21    public static IEnumerable<IResultFormatter> All { get; } =
22      PluginInfrastructure.ApplicationManager.Manager.GetInstances<IResultFormatter>();
23
24    /// <summary>
25    /// static method to get all existing result formatters for a specific type
26    /// </summary>
27    /// <param name="t">target type</param>
28    /// <returns>collection of found result formatters or null if none was found</returns>
29    public static IEnumerable<IResultFormatter> ForType(Type t) =>
30      All?.Where(x => x.CanFormatType(t)).OrderBy(x => x.Priority);
31  }
32}
Note: See TracBrowser for help on using the repository browser.