-
-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2013 from DGP-Studio/develop
- Loading branch information
Showing
226 changed files
with
4,095 additions
and
2,167 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
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
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
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
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
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
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
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
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
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
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,63 @@ | ||
// Copyright (c) DGP Studio. All rights reserved. | ||
// Licensed under the MIT license. | ||
|
||
using System.Collections; | ||
|
||
namespace Snap.Hutao.Core.Linq; | ||
|
||
internal sealed partial class DictionaryLookup<TKey, TEnumerable, TValue> : ILookup<TKey, TValue> | ||
where TKey : notnull | ||
where TEnumerable : IEnumerable<TValue> | ||
{ | ||
private readonly Dictionary<TKey, TEnumerable> inner; | ||
|
||
public DictionaryLookup(Dictionary<TKey, TEnumerable> source) | ||
{ | ||
inner = source; | ||
} | ||
|
||
public int Count { get => inner.Count; } | ||
|
||
public IEnumerable<TValue> this[TKey key] { get => inner[key]; } | ||
|
||
public bool Contains(TKey key) | ||
{ | ||
return inner.ContainsKey(key); | ||
} | ||
|
||
public IEnumerator<IGrouping<TKey, TValue>> GetEnumerator() | ||
{ | ||
foreach ((TKey key, TEnumerable values) in inner) | ||
{ | ||
yield return new Grouping(key, values); | ||
} | ||
} | ||
|
||
IEnumerator IEnumerable.GetEnumerator() | ||
{ | ||
return GetEnumerator(); | ||
} | ||
|
||
internal sealed class Grouping : IGrouping<TKey, TValue> | ||
{ | ||
private readonly TEnumerable enumerable; | ||
|
||
public Grouping(TKey key, TEnumerable enumerable) | ||
{ | ||
Key = key; | ||
this.enumerable = enumerable; | ||
} | ||
|
||
public TKey Key { get; } | ||
|
||
public IEnumerator<TValue> GetEnumerator() | ||
{ | ||
return enumerable.GetEnumerator(); | ||
} | ||
|
||
IEnumerator IEnumerable.GetEnumerator() | ||
{ | ||
return GetEnumerator(); | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/Snap.Hutao/Snap.Hutao/Core/Linq/DictionaryLookupExtension.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,13 @@ | ||
// Copyright (c) DGP Studio. All rights reserved. | ||
// Licensed under the MIT license. | ||
|
||
namespace Snap.Hutao.Core.Linq; | ||
|
||
internal static class DictionaryLookupExtension | ||
{ | ||
public static ILookup<TKey, TValue> ToLookup<TKey, TValue>(this Dictionary<TKey, List<TValue>> dictionary) | ||
where TKey : notnull | ||
{ | ||
return new DictionaryLookup<TKey, List<TValue>, TValue>(dictionary); | ||
} | ||
} |
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
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
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
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
Oops, something went wrong.