Last change
on this file since 17471 was
17394,
checked in by dpiringe, 5 years ago
|
#3026:
- deleted: ConvertableAttribute, DummyConverter, ObjectExtensions
- renamed: CustomJsonWriter -> SingleLineArrayJsonWriter, JCInstantiator -> JsonTemplateInstantiator
- added: JsonItemConverterFactory, UnsupportedJsonItem
- IJsonItemConverter:
- added two new properties: Priority and ConvertableType -> because converters are automatically collected by plugin infrastructure now
- Extract, Inject references a root converter now -> typically an instance of JsonItemConverter -> to prevent cycles
- JsonItemConverter:
- now implements the interface IJsonItemConverter
- is now a dynamic class
- is only instantiable with an factory (JsonItemConverterFactory)
- still has the old (but now public) static methods Extract and Inject (without ref param IJsonItemConverter root) -> creates instance with factory and calls methods of instance
- removed register and unregister methods, because the factory collects all converters automatically now (on first call of Create)
- has cycle detection for Extract and Inject
- renamed method Get to GetConverter
|
File size:
810 bytes
|
Line | |
---|
1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Text;
|
---|
5 | using System.Threading.Tasks;
|
---|
6 | using HeuristicLab.PluginInfrastructure;
|
---|
7 |
|
---|
8 | namespace HeuristicLab.JsonInterface {
|
---|
9 | public static class JsonItemConverterFactory {
|
---|
10 | private static IDictionary<Type, IJsonItemConverter> ConverterCache { get; set; }
|
---|
11 |
|
---|
12 | public static JsonItemConverter Create() {
|
---|
13 | if (ConverterCache == null)
|
---|
14 | InitCache();
|
---|
15 | return new JsonItemConverter(ConverterCache);
|
---|
16 | }
|
---|
17 |
|
---|
18 | private static void InitCache() {
|
---|
19 | ConverterCache = new Dictionary<Type, IJsonItemConverter>();
|
---|
20 | foreach (var converter in ApplicationManager.Manager.GetInstances<IJsonItemConverter>()) {
|
---|
21 | ConverterCache.Add(converter.ConvertableType, converter);
|
---|
22 | }
|
---|
23 | }
|
---|
24 | }
|
---|
25 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.