Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/LLTSharp/LLTParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,7 @@ private static void DeclareMainRules(ParserBuilder builder)
{
var obj = v.GetValue<TemplateDictionaryAccessor>(2);
var metadata = new List<IMetadata>();
var additionalMetadata = new AdditionalMetadata();

foreach (var pair in obj.Dictionary)
{
Expand All @@ -717,11 +718,14 @@ private static void DeclareMainRules(ParserBuilder builder)
metadata.Add(new VersionMetadata((int)((double)pair.Value.GetValue())));
break;
default:
metadata.Add(new AdditionalMetadata(pair.Key, pair.Value.GetValue()));
additionalMetadata.Set(pair.Key, pair.Value.GetValue());
break;
}
}

if (additionalMetadata.Count > 0)
metadata.Add(additionalMetadata.ToImmutable());

return new MetadataCollection(metadata);
});

Expand Down
2 changes: 1 addition & 1 deletion src/LLTSharp/LLTSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<PropertyGroup>
<PackageId>LLTSharp</PackageId>
<Version>1.2.0</Version>
<Version>1.2.1</Version>
<Authors>Roman K.</Authors>
<Company>RomeCore</Company>
<Product>LLTSharp</Product>
Expand Down
22 changes: 15 additions & 7 deletions src/LLTSharp/Metadata/IAdditionalMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,21 @@ namespace LLTSharp.Metadata
/// </summary>
public interface IAdditionalMetadata : IMetadata, IDynamicMetaObjectProvider
{
}
/// <summary>
/// Gets the value associated with the specified key.
/// </summary>
/// <typeparam name="T">The type to convert the value to.</typeparam>
/// <param name="key">The key of the value to get.</param>
/// <returns>The converted value or default(T) if not found.</returns>
T Get<T>(string key);

public static partial class MetadataExtensions
{
public static IAdditionalMetadata? TryGetAdditionalMetadata(this IMetadataProvider provider)
{
return provider.Metadata.TryGet<IAdditionalMetadata>();
}
/// <summary>
/// Tries to get the value associated with the specified key.
/// </summary>
/// <typeparam name="T">The type to convert the value to.</typeparam>
/// <param name="key">The key of the value to get.</param>
/// <param name="value">When this method returns, contains the value if found; otherwise, default(T).</param>
/// <returns>true if the key was found; otherwise, false.</returns>
bool TryGet<T>(string key, out T value);
}
}
13 changes: 13 additions & 0 deletions src/LLTSharp/Metadata/MetadataExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,18 @@ public static MetadataCollection ToMetadataCollection<T>(this IEnumerable<T> enu
{
return new MetadataCollection(enumerable.Cast<IMetadata>());
}

public static T? TryGetAdditional<T>(this IMetadataCollection collection, string key)
{
foreach (var metadata in collection.GetAll<IAdditionalMetadata>())
{
if (metadata.TryGet<T>(key, out var result))
{
return result;
}
}

return default;
}
}
}
Loading