add a scanner, but this seems to be a wrong solution. Change open-source head

This commit is contained in:
Youmu Liu
2026-07-07 18:20:38 +08:00
parent b053567eb7
commit 1705d7c245
276 changed files with 3468 additions and 7205 deletions
@@ -1,30 +1,10 @@
//-----------------------------------------------------------------------
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------------
// file="BidirectionalDictionary"
// Project: StgSharp
// AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
// Copyright (c) Nitload.
// SPDX-License-Identifier: MIT
// -----------------------------------------------------------------------------
using System;
using System.Collections;
using System.Collections.Generic;
@@ -34,8 +14,8 @@ using System.Linq;
namespace StgSharp.Collections
{
public sealed class BidirectionalDictionary<TFirst, TSecond> : IBidirectionalDictionary<TFirst, TSecond>
where TFirst: notnull
where TSecond: notnull
where TFirst : notnull
where TSecond : notnull
{
private readonly Dictionary<TFirst, TSecond> _forward;
@@ -47,7 +27,9 @@ namespace StgSharp.Collections
_reverse = [];
}
public TFirst this[TSecond key]
public TFirst this[
TSecond key
]
{
get => _reverse.TryGetValue(key, out TFirst value) ?
value :
@@ -66,7 +48,9 @@ namespace StgSharp.Collections
}
}
public TSecond this[TFirst key]
public TSecond this[
TFirst key
]
{
get => _forward.TryGetValue(key, out TSecond value) ?
value :
@@ -99,7 +83,9 @@ namespace StgSharp.Collections
public IReadOnlyDictionary<TSecond, TFirst> Reverse => new ReadOnlyDictionary<TSecond, TFirst>(
_reverse);
public void Add(KeyValuePair<TFirst, TSecond> item)
public void Add(
KeyValuePair<TFirst, TSecond> item
)
{
if (_forward.ContainsKey(item.Key) || _reverse.ContainsKey(item.Value)) {
throw new ArgumentException("Duplicate key or value.");
@@ -108,7 +94,10 @@ namespace StgSharp.Collections
_reverse.Add(item.Value, item.Key);
}
public void Add(TFirst key, TSecond value)
public void Add(
TFirst key,
TSecond value
)
{
if (_forward.ContainsKey(key) || _reverse.ContainsKey(value)) {
throw new ArgumentException("Duplicate key or value.");
@@ -123,22 +112,33 @@ namespace StgSharp.Collections
_reverse.Clear();
}
public bool Contains(KeyValuePair<TFirst, TSecond> item)
public bool Contains(
KeyValuePair<TFirst, TSecond> item
)
{
return _forward.Contains(item) && _reverse.TryGetValue(item.Value, out TFirst var) && var!.Equals(item.Key);
return _forward.Contains(item) &&
_reverse.TryGetValue(item.Value, out TFirst var) &&
var!.Equals(item.Key);
}
public bool Contains(TSecond key)
public bool Contains(
TSecond key
)
{
return _reverse.ContainsKey(key);
}
public bool Contains(TFirst key)
public bool Contains(
TFirst key
)
{
return _forward.ContainsKey(key);
}
public void CopyTo(KeyValuePair<TFirst, TSecond>[] array, int arrayIndex)
public void CopyTo(
KeyValuePair<TFirst, TSecond>[] array,
int arrayIndex
)
{
if (array == null) {
throw new ArgumentNullException(nameof(array));
@@ -162,12 +162,16 @@ namespace StgSharp.Collections
}
}
public bool Remove(TFirst key)
public bool Remove(
TFirst key
)
{
throw new NotImplementedException();
}
public bool Remove(KeyValuePair<TFirst, TSecond> item)
public bool Remove(
KeyValuePair<TFirst, TSecond> item
)
{
if (_forward.Remove(item.Key)) {
return _reverse.Remove(item.Value);
@@ -175,12 +179,18 @@ namespace StgSharp.Collections
return false;
}
public bool TryGetValue(TFirst key, out TSecond value)
public bool TryGetValue(
TFirst key,
out TSecond value
)
{
return _forward.TryGetValue(key, out value);
}
public bool TryGetValue(TSecond key, out TFirst value)
public bool TryGetValue(
TSecond key,
out TFirst value
)
{
return _reverse.TryGetValue(key, out value);
}