Skip to content

Commit

Permalink
custom collection converters
Browse files Browse the repository at this point in the history
  • Loading branch information
pshirshov committed Jan 9, 2025
1 parent d691292 commit 6995554
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
25 changes: 25 additions & 0 deletions src/main/resources/baboon-runtime/cs/BaboonRuntimeShared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,31 @@
// ReSharper disable UnusedType.Global

namespace Baboon.Runtime.Shared {
public static class BaboonEnumerable
{
public static List<TSource> BbnToList<TSource>(this IEnumerable<TSource> source)
{
if (source is List<TSource> l)
{
return l;
}

return source.ToList();
}

public static Dictionary<TKey, TElement> BbnToDictionary<TKey, TElement>(
this IEnumerable<KeyValuePair<TKey, TElement>> source)
where TKey : notnull
{
if (source is Dictionary<TKey, TElement> d)
{
return d;
}

return new Dictionary<TKey, TElement>(source);
}
}

public interface IBaboonGenerated {
public string BaboonDomainVersion();
public string BaboonDomainIdentifier();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ object CSTypes {

val debug: CSType = CSType(csDiagnosticsPkg, "Debug", fq = false)

val mkDict = q"ToDictionary(v => v.Key, v => v.Value)"
val mkList = q"ToList()"
val mkDict = q"BbnToDictionary()"
val mkList = q"BbnToList()"
val mkSet = q"ToImmutableHashSet()"
}

0 comments on commit 6995554

Please sign in to comment.