-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1dec0c5
commit 63cd484
Showing
4 changed files
with
76 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/RepoM.ActionMenu.Core/Yaml/Serialization/RequiredKeyValueTypeDiscriminator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
namespace RepoM.ActionMenu.Core.Yaml.Serialization; | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using Microsoft.Extensions.Logging; | ||
using YamlDotNet.Core; | ||
using YamlDotNet.Core.Events; | ||
using YamlDotNet.Serialization.BufferedDeserialization; | ||
using YamlDotNet.Serialization.BufferedDeserialization.TypeDiscriminators; | ||
|
||
internal class RequiredKeyValueTypeDiscriminator<TInterface> : ITypeDiscriminator | ||
where TInterface : class | ||
{ | ||
private readonly KeyValueTypeDiscriminator _discriminator; | ||
private readonly ILogger _logger; | ||
|
||
public RequiredKeyValueTypeDiscriminator(string key, IDictionary<string, Type> mapping, ILogger logger) | ||
{ | ||
_discriminator = new KeyValueTypeDiscriminator(typeof(TInterface), key, mapping); | ||
BaseType = typeof(TInterface); | ||
_logger = logger; | ||
} | ||
|
||
public Type BaseType { get; } | ||
|
||
public bool TryDiscriminate(IParser buffer, out Type? suggestedType) | ||
{ | ||
var result = _discriminator.TryDiscriminate(buffer, out suggestedType); | ||
|
||
if (!result) | ||
{ | ||
if (buffer.Current is Scalar scalar) | ||
{ | ||
_logger.LogError("Could not find required type. Type found {Type}", scalar.Value); | ||
} | ||
else | ||
{ | ||
_logger.LogError("Could not find required type"); | ||
} | ||
|
||
suggestedType = null; | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/RepoM.ActionMenu.Interface/YamlModel/DefaultMenuAction.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
namespace RepoM.ActionMenu.Interface.YamlModel; | ||
|
||
using RepoM.ActionMenu.Interface.YamlModel.Templating; | ||
|
||
public class DefaultMenuAction : IMenuAction | ||
{ | ||
public string Type { get; } | ||
|
||
public Predicate Active { get; } | ||
|
||
public DefaultMenuAction() | ||
{ | ||
Type = string.Empty; | ||
Active = new Predicate(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters