Class TypeExtension
Namespace: Tool.Utils
Assembly: Tool.Net.dll
对Type进行升级
public static class TypeExtensionInheritance
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
DefaultForType(Type)
获取当前类型的默认值
public static object DefaultForType(this Type type)Parameters
type Type
Returns
GetFieldKey(object, string, out bool)
获取指定变量值 (支持 public/private/protected) 静态时obj为null
public static object GetFieldKey(this object obj, string name, out bool isexist)Parameters
obj object
对象源
name string
变量名称
isexist bool
是否可以获取
Returns
返回变量值
GetFieldKey<T>(object, string, out bool)
获取指定变量值 (支持 public/private/protected) 静态时obj为null
public static object GetFieldKey<T>(this object obj, string name, out bool isexist)Parameters
obj object
对象源
name string
变量名称
isexist bool
是否可以获取
Returns
返回变量值
Type Parameters
T
GetFieldKey(object, Type, string, out bool)
获取指定变量值 (支持 public/private/protected) 静态时obj为null
public static object GetFieldKey(this object obj, Type type, string name, out bool isexist)Parameters
obj object
对象源
type Type
类型
name string
变量名称
isexist bool
是否可以获取
Returns
返回变量值
GetPropertieFind(object, string, bool)
获取当前对象下指定名称的属性对象
public static PropertyDescriptor GetPropertieFind(this object obj, string name, bool ignoreCase = false)Parameters
obj object
对象源
name string
属性名称
ignoreCase bool
是否忽略大小写
Returns
GetProperties(object)
获取当前对象下所有属性集合
public static PropertyDescriptorCollection GetProperties(this object obj)Parameters
obj object
对象源
Returns
属性集合
GetProperties(Type)
获取当前对象下所有属性集合
public static PropertyDescriptorCollection GetProperties(Type componentType)Parameters
componentType Type
对象源类型
Returns
属性集合
GetPropertyKey(object, string, out bool)
获取指定变量值 (支持 public/private/protected) 静态时obj为null
public static object GetPropertyKey(this object obj, string name, out bool isexist)Parameters
obj object
对象源
name string
变量名称
isexist bool
是否可以获取
Returns
返回变量值
GetPropertyKey<T>(object, string, out bool)
获取指定变量值 (支持 public/private/protected) 静态时obj为null
public static object GetPropertyKey<T>(this object obj, string name, out bool isexist)Parameters
obj object
对象源
name string
变量名称
isexist bool
是否可以获取
Returns
返回变量值
Type Parameters
T
GetPropertyKey(object, Type, string, out bool)
获取指定变量值 (支持 public/private/protected) 静态时obj为null
public static object GetPropertyKey(this object obj, Type type, string name, out bool isexist)Parameters
obj object
对象源
type Type
类型
name string
变量名称
isexist bool
是否可以获取
Returns
返回变量值
GetPropertys(Type)
获取公共管理的属性构造器
public static TypePropertyDescriptor GetPropertys(this Type type)Parameters
type Type
类型
Returns
属性构造器
GetValue(object, PropertyDescriptor)
根据属性对象获取属性的值
public static object GetValue(this object obj, PropertyDescriptor descriptor)Parameters
obj object
对象源
descriptor PropertyDescriptor
属性对象
Returns
属性值
GetValue(object, string, bool)
获取指定属性值
public static object GetValue(this object obj, string name, bool ignoreCase)Parameters
obj object
对象源
name string
属性名称
ignoreCase bool
是否忽略大小写
Returns
返回属性值
GetValue(object, string)
获取指定属性值(新模式)获取不到时 会抛出异常
public static object GetValue(this object obj, string name)Parameters
obj object
对象源
name string
属性名称
Returns
返回属性值
Exceptions
字段不存在时会报错!
InvokeAsync(Action)
创建异步返回模式
public static Task InvokeAsync(this Action @delegate)Parameters
delegate Action
Returns
InvokeAsync<T1>(Action<T1>, T1)
创建异步模式
public static Task InvokeAsync<T1>(this Action<T1> @delegate, T1 arg1)Parameters
delegate Action<T1>
arg1 T1
Returns
Type Parameters
T1
InvokeAsync<T1, T2>(Action<T1, T2>, T1, T2)
创建异步模式
public static Task InvokeAsync<T1, T2>(this Action<T1, T2> @delegate, T1 arg1, T2 arg2)Parameters
delegate Action<T1, T2>
arg1 T1
arg2 T2
Returns
Type Parameters
T1
T2
InvokeAsync<T1, T2, T3>(Action<T1, T2, T3>, T1, T2, T3)
创建异步模式
public static Task InvokeAsync<T1, T2, T3>(this Action<T1, T2, T3> @delegate, T1 arg1, T2 arg2, T3 arg3)Parameters
delegate Action<T1, T2, T3>
arg1 T1
arg2 T2
arg3 T3
Returns
Type Parameters
T1
T2
T3
InvokeAsync<T1, T2, T3, T4>(Action<T1, T2, T3, T4>, T1, T2, T3, T4)
创建异步模式
public static Task InvokeAsync<T1, T2, T3, T4>(this Action<T1, T2, T3, T4> @delegate, T1 arg1, T2 arg2, T3 arg3, T4 arg4)Parameters
delegate Action<T1, T2, T3, T4>
arg1 T1
arg2 T2
arg3 T3
arg4 T4
Returns
Type Parameters
T1
T2
T3
T4
InvokeAsync<T1, T2, T3, T4, T5>(Action<T1, T2, T3, T4, T5>, T1, T2, T3, T4, T5)
创建异步模式
public static Task InvokeAsync<T1, T2, T3, T4, T5>(this Action<T1, T2, T3, T4, T5> @delegate, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5)Parameters
delegate Action<T1, T2, T3, T4, T5>
arg1 T1
arg2 T2
arg3 T3
arg4 T4
arg5 T5
Returns
Type Parameters
T1
T2
T3
T4
T5
InvokeAsync<T1, T2, T3, T4, T5, T6>(Action<T1, T2, T3, T4, T5, T6>, T1, T2, T3, T4, T5, T6)
创建异步模式
public static Task InvokeAsync<T1, T2, T3, T4, T5, T6>(this Action<T1, T2, T3, T4, T5, T6> @delegate, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6)Parameters
delegate Action<T1, T2, T3, T4, T5, T6>
arg1 T1
arg2 T2
arg3 T3
arg4 T4
arg5 T5
arg6 T6
Returns
Type Parameters
T1
T2
T3
T4
T5
T6
InvokeAsync<T1, T2, T3, T4, T5, T6, T7>(Action<T1, T2, T3, T4, T5, T6, T7>, T1, T2, T3, T4, T5, T6, T7)
创建异步模式
public static Task InvokeAsync<T1, T2, T3, T4, T5, T6, T7>(this Action<T1, T2, T3, T4, T5, T6, T7> @delegate, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7)Parameters
delegate Action<T1, T2, T3, T4, T5, T6, T7>
arg1 T1
arg2 T2
arg3 T3
arg4 T4
arg5 T5
arg6 T6
arg7 T7
Returns
Type Parameters
T1
T2
T3
T4
T5
T6
T7
InvokeAsync<T1, T2, T3, T4, T5, T6, T7, T8>(Action<T1, T2, T3, T4, T5, T6, T7, T8>, T1, T2, T3, T4, T5, T6, T7, T8)
创建异步模式
public static Task InvokeAsync<T1, T2, T3, T4, T5, T6, T7, T8>(this Action<T1, T2, T3, T4, T5, T6, T7, T8> @delegate, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8)Parameters
delegate Action<T1, T2, T3, T4, T5, T6, T7, T8>
arg1 T1
arg2 T2
arg3 T3
arg4 T4
arg5 T5
arg6 T6
arg7 T7
arg8 T8
Returns
Type Parameters
T1
T2
T3
T4
T5
T6
T7
T8
InvokeAsync<T1, T2, T3, T4, T5, T6, T7, T8, T9>(Action<T1, T2, T3, T4, T5, T6, T7, T8, T9>, T1, T2, T3, T4, T5, T6, T7, T8, T9)
创建异步模式
public static Task InvokeAsync<T1, T2, T3, T4, T5, T6, T7, T8, T9>(this Action<T1, T2, T3, T4, T5, T6, T7, T8, T9> @delegate, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9)Parameters
delegate Action<T1, T2, T3, T4, T5, T6, T7, T8, T9>
arg1 T1
arg2 T2
arg3 T3
arg4 T4
arg5 T5
arg6 T6
arg7 T7
arg8 T8
arg9 T9
Returns
Type Parameters
T1
T2
T3
T4
T5
T6
T7
T8
T9
InvokeAsync<TResult>(Func<TResult>)
创建异步返回模式
public static Task<TResult> InvokeAsync<TResult>(this Func<TResult> @delegate)Parameters
delegate Func<TResult>
Returns
Task<TResult>
Type Parameters
TResult
InvokeAsync<T1, TResult>(Func<T1, TResult>, T1)
创建异步返回模式
public static Task<TResult> InvokeAsync<T1, TResult>(this Func<T1, TResult> @delegate, T1 arg1)Parameters
delegate Func<T1, TResult>
arg1 T1
Returns
Task<TResult>
Type Parameters
T1
TResult
InvokeAsync<T1, T2, TResult>(Func<T1, T2, TResult>, T1, T2)
创建异步返回模式
public static Task<TResult> InvokeAsync<T1, T2, TResult>(this Func<T1, T2, TResult> @delegate, T1 arg1, T2 arg2)Parameters
delegate Func<T1, T2, TResult>
arg1 T1
arg2 T2
Returns
Task<TResult>
Type Parameters
T1
T2
TResult
InvokeAsync<T1, T2, T3, TResult>(Func<T1, T2, T3, TResult>, T1, T2, T3)
创建异步返回模式
public static Task<TResult> InvokeAsync<T1, T2, T3, TResult>(this Func<T1, T2, T3, TResult> @delegate, T1 arg1, T2 arg2, T3 arg3)Parameters
delegate Func<T1, T2, T3, TResult>
arg1 T1
arg2 T2
arg3 T3
Returns
Task<TResult>
Type Parameters
T1
T2
T3
TResult
InvokeAsync<T1, T2, T3, T4, TResult>(Func<T1, T2, T3, T4, TResult>, T1, T2, T3, T4)
创建异步返回模式
public static Task<TResult> InvokeAsync<T1, T2, T3, T4, TResult>(this Func<T1, T2, T3, T4, TResult> @delegate, T1 arg1, T2 arg2, T3 arg3, T4 arg4)Parameters
delegate Func<T1, T2, T3, T4, TResult>
arg1 T1
arg2 T2
arg3 T3
arg4 T4
Returns
Task<TResult>
Type Parameters
T1
T2
T3
T4
TResult
InvokeAsync<T1, T2, T3, T4, T5, TResult>(Func<T1, T2, T3, T4, T5, TResult>, T1, T2, T3, T4, T5)
创建异步返回模式
public static Task<TResult> InvokeAsync<T1, T2, T3, T4, T5, TResult>(this Func<T1, T2, T3, T4, T5, TResult> @delegate, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5)Parameters
delegate Func<T1, T2, T3, T4, T5, TResult>
arg1 T1
arg2 T2
arg3 T3
arg4 T4
arg5 T5
Returns
Task<TResult>
Type Parameters
T1
T2
T3
T4
T5
TResult
InvokeAsync<T1, T2, T3, T4, T5, T6, TResult>(Func<T1, T2, T3, T4, T5, T6, TResult>, T1, T2, T3, T4, T5, T6)
创建异步返回模式
public static Task<TResult> InvokeAsync<T1, T2, T3, T4, T5, T6, TResult>(this Func<T1, T2, T3, T4, T5, T6, TResult> @delegate, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6)Parameters
delegate Func<T1, T2, T3, T4, T5, T6, TResult>
arg1 T1
arg2 T2
arg3 T3
arg4 T4
arg5 T5
arg6 T6
Returns
Task<TResult>
Type Parameters
T1
T2
T3
T4
T5
T6
TResult
InvokeAsync<T1, T2, T3, T4, T5, T6, T7, TResult>(Func<T1, T2, T3, T4, T5, T6, T7, TResult>, T1, T2, T3, T4, T5, T6, T7)
创建异步返回模式
public static Task<TResult> InvokeAsync<T1, T2, T3, T4, T5, T6, T7, TResult>(this Func<T1, T2, T3, T4, T5, T6, T7, TResult> @delegate, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7)Parameters
delegate Func<T1, T2, T3, T4, T5, T6, T7, TResult>
arg1 T1
arg2 T2
arg3 T3
arg4 T4
arg5 T5
arg6 T6
arg7 T7
Returns
Task<TResult>
Type Parameters
T1
T2
T3
T4
T5
T6
T7
TResult
InvokeAsync<T1, T2, T3, T4, T5, T6, T7, T8, TResult>(Func<T1, T2, T3, T4, T5, T6, T7, T8, TResult>, T1, T2, T3, T4, T5, T6, T7, T8)
创建异步返回模式
public static Task<TResult> InvokeAsync<T1, T2, T3, T4, T5, T6, T7, T8, TResult>(this Func<T1, T2, T3, T4, T5, T6, T7, T8, TResult> @delegate, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8)Parameters
delegate Func<T1, T2, T3, T4, T5, T6, T7, T8, TResult>
arg1 T1
arg2 T2
arg3 T3
arg4 T4
arg5 T5
arg6 T6
arg7 T7
arg8 T8
Returns
Task<TResult>
Type Parameters
T1
T2
T3
T4
T5
T6
T7
T8
TResult
InvokeAsync<T1, T2, T3, T4, T5, T6, T7, T8, T9, TResult>(Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, TResult>, T1, T2, T3, T4, T5, T6, T7, T8, T9)
创建异步返回模式
public static Task<TResult> InvokeAsync<T1, T2, T3, T4, T5, T6, T7, T8, T9, TResult>(this Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, TResult> @delegate, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9)Parameters
delegate Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, TResult>
arg1 T1
arg2 T2
arg3 T3
arg4 T4
arg5 T5
arg6 T6
arg7 T7
arg8 T8
arg9 T9
Returns
Task<TResult>
Type Parameters
T1
T2
T3
T4
T5
T6
T7
T8
T9
TResult
IsDictionary(Type)
判断是否是字典类型
public static bool IsDictionary(this Type type)Parameters
type Type
类型
Returns
IsNumber(Type)
验证是否是数字类型
public static bool IsNumber(this Type type)Parameters
type Type
Returns
IsString(Type)
验证是否是字符类型
public static bool IsString(this Type type)Parameters
type Type
Returns
IsType(Type)
验证是否是系统变量
public static bool IsType(this Type type)Parameters
type Type
Returns
SetFieldKey(object, string, object)
修改指定变量值 (支持 public/private/protected) 静态时obj为null
public static bool SetFieldKey(this object obj, string name, object value)Parameters
obj object
对象源
name string
变量名称
value object
修改的值
Returns
返回是否查找到并进行修改
SetFieldKey<T>(object, string, object)
修改指定变量值 (支持 public/private/protected) 静态时obj为null
public static bool SetFieldKey<T>(this object obj, string name, object value)Parameters
obj object
对象源
name string
变量名称
value object
修改的值
Returns
返回是否查找到并进行修改
Type Parameters
T
SetFieldKey(object, Type, string, object)
修改指定变量值 (支持 public/private/protected) 静态时obj为null
public static bool SetFieldKey(this object obj, Type type, string name, object value)Parameters
obj object
对象源
type Type
类型
name string
变量名称
value object
修改的值
Returns
返回是否查找到并进行修改
SetPropertyKey(object, string, object)
修改指定变量值 (支持 public/private/protected) 静态时obj为null
public static bool SetPropertyKey(this object obj, string name, object value)Parameters
obj object
对象源
name string
变量名称
value object
修改的值
Returns
返回是否查找到并进行修改
SetPropertyKey<T>(object, string, object)
修改指定变量值 (支持 public/private/protected) 静态时obj为null
public static bool SetPropertyKey<T>(this object obj, string name, object value)Parameters
obj object
对象源
name string
变量名称
value object
修改的值
Returns
返回是否查找到并进行修改
Type Parameters
T
SetPropertyKey(object, Type, string, object)
修改指定变量值 (支持 public/private/protected) 静态时obj为null
public static bool SetPropertyKey(this object obj, Type type, string name, object value)Parameters
obj object
对象源
type Type
类型
name string
变量名称
value object
修改的值
Returns
返回是否查找到并进行修改
SetValue(object, PropertyDescriptor, object)
根据属性对象修改属性的值
public static void SetValue(this object obj, PropertyDescriptor descriptor, object value)Parameters
obj object
对象源
descriptor PropertyDescriptor
属性对象
value object
修改属性的值
SetValue(object, string, object, bool)
修改指定属性值
public static bool SetValue(this object obj, string name, object value, bool ignoreCase)Parameters
obj object
对象源
name string
属性名称
value object
修改的值
ignoreCase bool
是否忽略大小写
Returns
返回是否查找到并进行修改
SetValue(object, string, object)
修改指定属性值(新模式)
public static bool SetValue(this object obj, string name, object value)Parameters
obj object
对象源
name string
属性名称
value object
修改的值
Returns
返回是否查找到并进行修改