CombinedEnumAndIndex
This commit is contained in:
@ -1,3 +1,4 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
@ -83,6 +84,33 @@ public record FilePath(long CreationTicks,
|
||||
return result;
|
||||
}
|
||||
|
||||
public static ReadOnlyDictionary<int, ReadOnlyCollection<FilePath>> GetKeyValuePairs(ReadOnlyCollection<ReadOnlyCollection<FilePath>> filePathsCollection)
|
||||
{
|
||||
Dictionary<int, ReadOnlyCollection<FilePath>> results = [];
|
||||
List<FilePath>? collection;
|
||||
Dictionary<int, List<FilePath>> keyValuePairs = [];
|
||||
foreach (ReadOnlyCollection<FilePath> filePaths in filePathsCollection)
|
||||
{
|
||||
if (filePaths.Count == 0)
|
||||
continue;
|
||||
foreach (FilePath filePath in filePaths)
|
||||
{
|
||||
if (filePath.Id is null)
|
||||
continue;
|
||||
if (!keyValuePairs.TryGetValue(filePath.Id.Value, out collection))
|
||||
{
|
||||
keyValuePairs.Add(filePath.Id.Value, []);
|
||||
if (!keyValuePairs.TryGetValue(filePath.Id.Value, out collection))
|
||||
throw new Exception();
|
||||
}
|
||||
collection.Add(filePath);
|
||||
}
|
||||
}
|
||||
foreach (KeyValuePair<int, List<FilePath>> keyValuePair in keyValuePairs)
|
||||
results.Add(keyValuePair.Key, new(keyValuePair.Value));
|
||||
return results.AsReadOnly();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[JsonSourceGenerationOptions(WriteIndented = true)]
|
||||
|
Reference in New Issue
Block a user