code clean up

This commit is contained in:
Youmu Liu
2025-10-17 10:49:00 +08:00
parent d3e0b5d005
commit 1927f4fdf3
223 changed files with 5675 additions and 6160 deletions
@@ -1,33 +1,30 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="PartialDictionary.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
// -----------------------------------------------------------------------
// file="PartialDictionary"
// 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:
// 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.
//
// 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.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
using System;
using System.Collections;
using System.Collections.Generic;
@@ -45,61 +42,58 @@ namespace StgSharp.Collections
private readonly HashSet<TKey> _keys;
private readonly PartialDictionaryValues _values;
public PartialDictionary( Dictionary<TKey, TValue> source, TKey[] index )
public PartialDictionary(Dictionary<TKey, TValue> source, TKey[] index)
{
_source = source;
_keys = new HashSet<TKey>( index );
foreach( TKey item in _keys )
_keys = new HashSet<TKey>(index);
foreach (TKey item in _keys)
{
if( !_source.ContainsKey( item ) ) {
_source.Add( item, default! );
if (!_source.ContainsKey(item)) {
_source.Add(item, default!);
}
}
_values = new PartialDictionaryValues( this );
_values = new PartialDictionaryValues(this);
}
public PartialDictionary( Dictionary<TKey, TValue> source, HashSet<TKey> keys )
public PartialDictionary(Dictionary<TKey, TValue> source, HashSet<TKey> keys)
{
_source = source;
_keys = keys;
foreach( TKey item in _keys )
foreach (TKey item in _keys)
{
if( !_source.ContainsKey( item ) ) {
_source.Add( item, default! );
if (!_source.ContainsKey(item)) {
_source.Add(item, default!);
}
}
_values = new PartialDictionaryValues( this );
_values = new PartialDictionaryValues(this);
}
public PartialDictionary(
Dictionary<TKey, TValue> source,
TKey[] index,
IHashMultiplexer<TKey> multiplexer )
public PartialDictionary(Dictionary<TKey, TValue> source, TKey[] index, IHashMultiplexer<TKey> multiplexer)
{
_source = source;
_keys = new HashSet<TKey>( index );
foreach( TKey item in _keys )
_keys = new HashSet<TKey>(index);
foreach (TKey item in _keys)
{
if( !_source.ContainsKey( item ) ) {
_source.Add( item, default! );
if (!_source.ContainsKey(item)) {
_source.Add(item, default!);
}
}
_values = new PartialDictionaryValues( this );
_values = new PartialDictionaryValues(this);
}
public TValue this[ TKey key ]
public TValue this[TKey key]
{
get
{
if( _keys.Contains( key ) ) {
return _source[ key ];
if (_keys.Contains(key)) {
return _source[key];
}
throw new KeyNotFoundException();
}
set
{
if( _keys.Contains( key ) ) {
_source[ key ] = value;
if (_keys.Contains(key)) {
_source[key] = value;
}
throw new KeyNotFoundException();
}
@@ -111,40 +105,40 @@ namespace StgSharp.Collections
public int Count => _keys.Count;
public bool Contains( KeyValuePair<TKey, TValue> item )
public bool Contains(KeyValuePair<TKey, TValue> item)
{
return _keys.Contains( item.Key ) && _source.Contains( item );
return _keys.Contains(item.Key) && _source.Contains(item);
}
public bool ContainsKey( TKey key )
public bool ContainsKey(TKey key)
{
return _keys.Contains( key );
return _keys.Contains(key);
}
public void CopyTo( KeyValuePair<TKey, TValue>[] array, int arrayIndex )
public void CopyTo(KeyValuePair<TKey, TValue>[] array, int arrayIndex)
{
throw new NotImplementedException();
}
public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator()
{
foreach( TKey item in _keys ) {
yield return new KeyValuePair<TKey, TValue>( item, _source[ item ] );
foreach (TKey item in _keys) {
yield return new KeyValuePair<TKey, TValue>(item, _source[item]);
}
}
public bool TryGetValue( TKey key, out TValue value )
public bool TryGetValue(TKey key, out TValue value)
{
if( _keys.Contains( key ) )
if (_keys.Contains(key))
{
value = _source[ key ];
value = _source[key];
return true;
}
value = default!;
return false;
}
void ICollection<KeyValuePair<TKey, TValue>>.Add( KeyValuePair<TKey, TValue> item )
void ICollection<KeyValuePair<TKey, TValue>>.Add(KeyValuePair<TKey, TValue> item)
{
return;
}
@@ -154,19 +148,19 @@ namespace StgSharp.Collections
throw new NotSupportedException();
}
bool ICollection<KeyValuePair<TKey, TValue>>.Remove( KeyValuePair<TKey, TValue> item )
bool ICollection<KeyValuePair<TKey, TValue>>.Remove(KeyValuePair<TKey, TValue> item)
{
throw new NotSupportedException();
}
bool ICollection<KeyValuePair<TKey, TValue>>.IsReadOnly => true;
void IDictionary<TKey, TValue>.Add( TKey key, TValue value )
void IDictionary<TKey, TValue>.Add(TKey key, TValue value)
{
return;
}
bool IDictionary<TKey, TValue>.Remove( TKey key )
bool IDictionary<TKey, TValue>.Remove(TKey key)
{
throw new NotSupportedException();
}