Free cookie consent management tool by TermsFeed Policy Generator

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

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

#3026

  • code cleanup
File size: 1.0 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4
5namespace HeuristicLab.JsonInterface {
6
7  /// <summary>
8  /// Base Class for ResultFormatter
9  /// </summary>
10  public abstract class ResultFormatter : IResultFormatter {
11    public abstract int Priority { get; }
12    public abstract bool CanFormatType(Type t);
13    public abstract string Format(object o);
14
15    /// <summary>
16    /// static property to get all existing result formatters
17    /// </summary>
18    public static IEnumerable<IResultFormatter> All { get; } =
19      PluginInfrastructure.ApplicationManager.Manager.GetInstances<IResultFormatter>();
20
21    /// <summary>
22    /// static method to get all existing result formatters for a specific type
23    /// </summary>
24    /// <param name="t">target type</param>
25    /// <returns>collection of found result formatters or null if none was found</returns>
26    public static IEnumerable<IResultFormatter> ForType(Type t) =>
27      All?.Where(x => x.CanFormatType(t)).OrderBy(x => x.Priority);
28  }
29}
Note: See TracBrowser for help on using the repository browser.