Skip to content

Class DictionaryExtension ​

Namespace: Tool.Utils.Data
Assembly: Tool.Net.dll

对Dictionary进行升级

csharp
public static class DictionaryExtension

Inheritance ​

object ← DictionaryExtension

Inherited Members ​

object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.MemberwiseClone(), object.ReferenceEquals(object?, object?), object.ToString()

Extension Methods ​

ObjectExtension.Add<T>(object, object, object), ObjectExtension.CopyEntity(object, object, params string[]), ObjectExtension.EntityToJson(object), ObjectExtension.EntityToJson(object, bool), ObjectExtension.EntityToJson(object, bool, string), DictionaryExtension.GetDictionary(object), TypeExtension.GetFieldKey(object, string, out bool), TypeExtension.GetFieldKey<T>(object, string, out bool), TypeExtension.GetFieldKey(object, Type, string, out bool), ObjectExtension.GetIntPtr(object), ObjectExtension.GetIntPtrInt(object), TypeExtension.GetPropertieFind(object, string, bool), TypeExtension.GetProperties(object), TypeExtension.GetPropertyKey(object, string, out bool), TypeExtension.GetPropertyKey<T>(object, string, out bool), TypeExtension.GetPropertyKey(object, Type, string, out bool), TypeExtension.GetValue(object, PropertyDescriptor), TypeExtension.GetValue(object, string, bool), TypeExtension.GetValue(object, string), ObjectExtension.Read<T>(object, object, int, int), ObjectExtension.Read<T>(object, int, object, int, int), DictionaryExtension.SetDictionary(object, IDictionary<string, object>), TypeExtension.SetFieldKey(object, string, object), TypeExtension.SetFieldKey<T>(object, string, object), TypeExtension.SetFieldKey(object, Type, string, object), TypeExtension.SetPropertyKey(object, string, object), TypeExtension.SetPropertyKey<T>(object, string, object), TypeExtension.SetPropertyKey(object, Type, string, object), TypeExtension.SetValue(object, PropertyDescriptor, object), TypeExtension.SetValue(object, string, object, bool), TypeExtension.SetValue(object, string, object), ObjectExtension.ToBase64String(object), ObjectExtension.ToBytes(object), ObjectExtension.ToBytes(object, out Type), DictionaryExtension.ToDictionary(object), DictionaryExtension.ToDictionary<T>(object), DictionaryExtension.ToIDictionary(object), DictionaryExtension.ToIDictionary<T>(object), ObjectExtension.ToJson(object), ObjectExtension.ToJson(object, JsonSerializerOptions), ObjectExtension.ToJsonWeb(object), ObjectExtension.ToJsonWeb(object, Action<JsonSerializerOptions>), ObjectExtension.ToTryVar<T>(object, T), ObjectExtension.ToVar<T>(object), ObjectExtension.ToVar(object, Type, bool), ObjectExtension.ToVar(object, string), ObjectExtension.ToXml(object)

Remarks ​

代码由逆血提供支持

Methods ​

AsReadOnly<TKey, TValue>(IDictionary<TKey, TValue>) ​

将键值对转换成只读类型键值对

csharp
public static ReadOnlyDictionary<TKey, TValue> AsReadOnly<TKey, TValue>(this IDictionary<TKey, TValue> keys)

Parameters ​

keys IDictionary<TKey, TValue>

原本键值对

Returns ​

ReadOnlyDictionary<TKey, TValue>

只读键值对

Type Parameters ​

TKey

键

TValue

值

GetArrayIndex<TKey, TValue>(Dictionary<TKey, TValue>, int, int) ​

同于获取指定部分的内容

csharp
public static Dictionary<TKey, TValue> GetArrayIndex<TKey, TValue>(this Dictionary<TKey, TValue> keyValuePairs, int index, int count) where TKey : new() where TValue : new()

Parameters ​

keyValuePairs Dictionary<TKey, TValue>

对象数组

index int

从下标N开始

count int

到下标N结束

Returns ​

Dictionary<TKey, TValue>

返回一部分的数组内容

Type Parameters ​

TKey

TValue

GetDictionary(object) ​

获取对象结果集

csharp
public static IDictionary<string, object> GetDictionary(this object source)

Parameters ​

source object

对象

Returns ​

IDictionary<string, object>

对象结果集

GetParamAscii<TKey, TValue>(Dictionary<TKey, TValue>) ​

按照ASCII码从小到大排序(示例: 1, 2, A, B, a, b 这是格式循序)

csharp
public static Dictionary<TKey, TValue> GetParamAscii<TKey, TValue>(this Dictionary<TKey, TValue> keyValuePairs)

Parameters ​

keyValuePairs Dictionary<TKey, TValue>

Dictionary

Returns ​

Dictionary<TKey, TValue>

返回重新排序好的结果

Type Parameters ​

TKey

TValue

NewDictionary<TKey, TValue>(IDictionary<TKey, TValue>) ​

将 对象 拷贝创建新 对象

csharp
public static Dictionary<TKey, TValue> NewDictionary<TKey, TValue>(this IDictionary<TKey, TValue> oldDictionary)

Parameters ​

oldDictionary IDictionary<TKey, TValue>

对象

Returns ​

Dictionary<TKey, TValue>

Type Parameters ​

TKey

键

TValue

值

Remove<TKey, TValue>(IDictionary<TKey, TValue>, params TKey[]) ​

批量删除 对象 出现不包含的会返回 false

csharp
public static bool Remove<TKey, TValue>(this IDictionary<TKey, TValue> keys, params TKey[] key)

Parameters ​

keys IDictionary<TKey, TValue>

对象

key TKey[]

需要删除的键值集合

Returns ​

bool

Type Parameters ​

TKey

键

TValue

值

SetDictionary(object, IDictionary<string, object>) ​

给对象赋值,使用字典赋值

csharp
public static void SetDictionary(this object source, IDictionary<string, object> parameters)

Parameters ​

source object

对象

parameters IDictionary<string, object>

赋值键值对

ToDictionary(object) ​

将对象转换成

csharp
public static Dictionary<string, object> ToDictionary(this object source)

Parameters ​

source object

对象

Returns ​

Dictionary<string, object>

ToDictionary<T>(object) ​

将对象转换成

csharp
public static Dictionary<string, T> ToDictionary<T>(this object source)

Parameters ​

source object

对象

Returns ​

Dictionary<string, T>

Type Parameters ​

T

ToIDictionary(object) ​

将对象转换成

csharp
public static IDictionary<string, object> ToIDictionary(this object source)

Parameters ​

source object

对象

Returns ​

IDictionary<string, object>

ToIDictionary<T>(object) ​

将对象转换成

csharp
public static IDictionary<string, T> ToIDictionary<T>(this object source)

Parameters ​

source object

对象

Returns ​

IDictionary<string, T>

Type Parameters ​

T

TryRemove<TKey, TValue>(IDictionary<TKey, TValue>, out TKey[], params TKey[]) ​

批量删除 对象 中的值

csharp
public static bool TryRemove<TKey, TValue>(this IDictionary<TKey, TValue> keys, out TKey[] trykey, params TKey[] key)

Parameters ​

keys IDictionary<TKey, TValue>

对象

trykey TKey[]

删除失败时返回无法删除的哪些项。

key TKey[]

需要删除的键值集合

Returns ​

bool

Type Parameters ​

TKey

键

TValue

值

基于Apache-2.0协议开源