455 lines
13 KiB
C#
455 lines
13 KiB
C#
using System;
|
|
using System.CodeDom.Compiler;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Globalization;
|
|
using System.Reflection;
|
|
|
|
namespace SimpleJson.Reflection
|
|
{
|
|
// Token: 0x020002E6 RID: 742
|
|
[GeneratedCode("reflection-utils", "1.0.0")]
|
|
internal class ReflectionUtils
|
|
{
|
|
// Token: 0x060030BB RID: 12475 RVA: 0x00048CB8 File Offset: 0x00046EB8
|
|
public static Attribute GetAttribute(MemberInfo info, Type type)
|
|
{
|
|
Attribute attribute;
|
|
if (info == null || type == null || !Attribute.IsDefined(info, type))
|
|
{
|
|
attribute = null;
|
|
}
|
|
else
|
|
{
|
|
attribute = Attribute.GetCustomAttribute(info, type);
|
|
}
|
|
return attribute;
|
|
}
|
|
|
|
// Token: 0x060030BC RID: 12476 RVA: 0x00048CF4 File Offset: 0x00046EF4
|
|
public static Attribute GetAttribute(Type objectType, Type attributeType)
|
|
{
|
|
Attribute attribute;
|
|
if (objectType == null || attributeType == null || !Attribute.IsDefined(objectType, attributeType))
|
|
{
|
|
attribute = null;
|
|
}
|
|
else
|
|
{
|
|
attribute = Attribute.GetCustomAttribute(objectType, attributeType);
|
|
}
|
|
return attribute;
|
|
}
|
|
|
|
// Token: 0x060030BD RID: 12477 RVA: 0x00048D30 File Offset: 0x00046F30
|
|
public static Type[] GetGenericTypeArguments(Type type)
|
|
{
|
|
return type.GetGenericArguments();
|
|
}
|
|
|
|
// Token: 0x060030BE RID: 12478 RVA: 0x00048D4C File Offset: 0x00046F4C
|
|
public static bool IsTypeGenericeCollectionInterface(Type type)
|
|
{
|
|
bool flag;
|
|
if (!type.IsGenericType)
|
|
{
|
|
flag = false;
|
|
}
|
|
else
|
|
{
|
|
Type genericTypeDefinition = type.GetGenericTypeDefinition();
|
|
flag = genericTypeDefinition == typeof(IList<>) || genericTypeDefinition == typeof(ICollection<>) || genericTypeDefinition == typeof(IEnumerable<>);
|
|
}
|
|
return flag;
|
|
}
|
|
|
|
// Token: 0x060030BF RID: 12479 RVA: 0x00048DAC File Offset: 0x00046FAC
|
|
public static bool IsAssignableFrom(Type type1, Type type2)
|
|
{
|
|
return type1.IsAssignableFrom(type2);
|
|
}
|
|
|
|
// Token: 0x060030C0 RID: 12480 RVA: 0x00048DC8 File Offset: 0x00046FC8
|
|
public static bool IsTypeDictionary(Type type)
|
|
{
|
|
bool flag;
|
|
if (typeof(IDictionary).IsAssignableFrom(type))
|
|
{
|
|
flag = true;
|
|
}
|
|
else if (!type.IsGenericType)
|
|
{
|
|
flag = false;
|
|
}
|
|
else
|
|
{
|
|
Type genericTypeDefinition = type.GetGenericTypeDefinition();
|
|
flag = genericTypeDefinition == typeof(IDictionary<, >);
|
|
}
|
|
return flag;
|
|
}
|
|
|
|
// Token: 0x060030C1 RID: 12481 RVA: 0x00048E20 File Offset: 0x00047020
|
|
public static bool IsNullableType(Type type)
|
|
{
|
|
return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>);
|
|
}
|
|
|
|
// Token: 0x060030C2 RID: 12482 RVA: 0x00048E58 File Offset: 0x00047058
|
|
public static object ToNullableType(object obj, Type nullableType)
|
|
{
|
|
return (obj != null) ? Convert.ChangeType(obj, Nullable.GetUnderlyingType(nullableType), CultureInfo.InvariantCulture) : null;
|
|
}
|
|
|
|
// Token: 0x060030C3 RID: 12483 RVA: 0x00048E8C File Offset: 0x0004708C
|
|
public static bool IsValueType(Type type)
|
|
{
|
|
return type.IsValueType;
|
|
}
|
|
|
|
// Token: 0x060030C4 RID: 12484 RVA: 0x00048EA8 File Offset: 0x000470A8
|
|
public static IEnumerable<ConstructorInfo> GetConstructors(Type type)
|
|
{
|
|
return type.GetConstructors();
|
|
}
|
|
|
|
// Token: 0x060030C5 RID: 12485 RVA: 0x00048EC4 File Offset: 0x000470C4
|
|
public static ConstructorInfo GetConstructorInfo(Type type, params Type[] argsType)
|
|
{
|
|
IEnumerable<ConstructorInfo> constructors = ReflectionUtils.GetConstructors(type);
|
|
foreach (ConstructorInfo constructorInfo in constructors)
|
|
{
|
|
ParameterInfo[] parameters = constructorInfo.GetParameters();
|
|
if (argsType.Length == parameters.Length)
|
|
{
|
|
int num = 0;
|
|
bool flag = true;
|
|
foreach (ParameterInfo parameterInfo in constructorInfo.GetParameters())
|
|
{
|
|
if (parameterInfo.ParameterType != argsType[num])
|
|
{
|
|
flag = false;
|
|
break;
|
|
}
|
|
}
|
|
if (flag)
|
|
{
|
|
return constructorInfo;
|
|
}
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
// Token: 0x060030C6 RID: 12486 RVA: 0x00048F98 File Offset: 0x00047198
|
|
public static IEnumerable<PropertyInfo> GetProperties(Type type)
|
|
{
|
|
return type.GetProperties(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
|
|
}
|
|
|
|
// Token: 0x060030C7 RID: 12487 RVA: 0x00048FB8 File Offset: 0x000471B8
|
|
public static IEnumerable<FieldInfo> GetFields(Type type)
|
|
{
|
|
return type.GetFields(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
|
|
}
|
|
|
|
// Token: 0x060030C8 RID: 12488 RVA: 0x00048FD8 File Offset: 0x000471D8
|
|
public static MethodInfo GetGetterMethodInfo(PropertyInfo propertyInfo)
|
|
{
|
|
return propertyInfo.GetGetMethod(true);
|
|
}
|
|
|
|
// Token: 0x060030C9 RID: 12489 RVA: 0x00048FF4 File Offset: 0x000471F4
|
|
public static MethodInfo GetSetterMethodInfo(PropertyInfo propertyInfo)
|
|
{
|
|
return propertyInfo.GetSetMethod(true);
|
|
}
|
|
|
|
// Token: 0x060030CA RID: 12490 RVA: 0x00049010 File Offset: 0x00047210
|
|
public static ReflectionUtils.ConstructorDelegate GetContructor(ConstructorInfo constructorInfo)
|
|
{
|
|
return ReflectionUtils.GetConstructorByReflection(constructorInfo);
|
|
}
|
|
|
|
// Token: 0x060030CB RID: 12491 RVA: 0x0004902C File Offset: 0x0004722C
|
|
public static ReflectionUtils.ConstructorDelegate GetContructor(Type type, params Type[] argsType)
|
|
{
|
|
return ReflectionUtils.GetConstructorByReflection(type, argsType);
|
|
}
|
|
|
|
// Token: 0x060030CC RID: 12492 RVA: 0x00049048 File Offset: 0x00047248
|
|
public static ReflectionUtils.ConstructorDelegate GetConstructorByReflection(ConstructorInfo constructorInfo)
|
|
{
|
|
return (object[] args) => constructorInfo.Invoke(args);
|
|
}
|
|
|
|
// Token: 0x060030CD RID: 12493 RVA: 0x00049078 File Offset: 0x00047278
|
|
public static ReflectionUtils.ConstructorDelegate GetConstructorByReflection(Type type, params Type[] argsType)
|
|
{
|
|
ConstructorInfo constructorInfo = ReflectionUtils.GetConstructorInfo(type, argsType);
|
|
return (constructorInfo != null) ? ReflectionUtils.GetConstructorByReflection(constructorInfo) : null;
|
|
}
|
|
|
|
// Token: 0x060030CE RID: 12494 RVA: 0x000490A8 File Offset: 0x000472A8
|
|
public static ReflectionUtils.GetDelegate GetGetMethod(PropertyInfo propertyInfo)
|
|
{
|
|
return ReflectionUtils.GetGetMethodByReflection(propertyInfo);
|
|
}
|
|
|
|
// Token: 0x060030CF RID: 12495 RVA: 0x000490C4 File Offset: 0x000472C4
|
|
public static ReflectionUtils.GetDelegate GetGetMethod(FieldInfo fieldInfo)
|
|
{
|
|
return ReflectionUtils.GetGetMethodByReflection(fieldInfo);
|
|
}
|
|
|
|
// Token: 0x060030D0 RID: 12496 RVA: 0x000490E0 File Offset: 0x000472E0
|
|
public static ReflectionUtils.GetDelegate GetGetMethodByReflection(PropertyInfo propertyInfo)
|
|
{
|
|
MethodInfo methodInfo = ReflectionUtils.GetGetterMethodInfo(propertyInfo);
|
|
return (object source) => methodInfo.Invoke(source, ReflectionUtils.EmptyObjects);
|
|
}
|
|
|
|
// Token: 0x060030D1 RID: 12497 RVA: 0x00049114 File Offset: 0x00047314
|
|
public static ReflectionUtils.GetDelegate GetGetMethodByReflection(FieldInfo fieldInfo)
|
|
{
|
|
return (object source) => fieldInfo.GetValue(source);
|
|
}
|
|
|
|
// Token: 0x060030D2 RID: 12498 RVA: 0x00049144 File Offset: 0x00047344
|
|
public static ReflectionUtils.SetDelegate GetSetMethod(PropertyInfo propertyInfo)
|
|
{
|
|
return ReflectionUtils.GetSetMethodByReflection(propertyInfo);
|
|
}
|
|
|
|
// Token: 0x060030D3 RID: 12499 RVA: 0x00049160 File Offset: 0x00047360
|
|
public static ReflectionUtils.SetDelegate GetSetMethod(FieldInfo fieldInfo)
|
|
{
|
|
return ReflectionUtils.GetSetMethodByReflection(fieldInfo);
|
|
}
|
|
|
|
// Token: 0x060030D4 RID: 12500 RVA: 0x0004917C File Offset: 0x0004737C
|
|
public static ReflectionUtils.SetDelegate GetSetMethodByReflection(PropertyInfo propertyInfo)
|
|
{
|
|
MethodInfo methodInfo = ReflectionUtils.GetSetterMethodInfo(propertyInfo);
|
|
return delegate(object source, object value)
|
|
{
|
|
methodInfo.Invoke(source, new object[] { value });
|
|
};
|
|
}
|
|
|
|
// Token: 0x060030D5 RID: 12501 RVA: 0x000491B0 File Offset: 0x000473B0
|
|
public static ReflectionUtils.SetDelegate GetSetMethodByReflection(FieldInfo fieldInfo)
|
|
{
|
|
return delegate(object source, object value)
|
|
{
|
|
fieldInfo.SetValue(source, value);
|
|
};
|
|
}
|
|
|
|
// Token: 0x040009A6 RID: 2470
|
|
private static readonly object[] EmptyObjects = new object[0];
|
|
|
|
// Token: 0x020002E7 RID: 743
|
|
// (Invoke) Token: 0x060030D8 RID: 12504
|
|
public delegate object GetDelegate(object source);
|
|
|
|
// Token: 0x020002E8 RID: 744
|
|
// (Invoke) Token: 0x060030DC RID: 12508
|
|
public delegate void SetDelegate(object source, object value);
|
|
|
|
// Token: 0x020002E9 RID: 745
|
|
// (Invoke) Token: 0x060030E0 RID: 12512
|
|
public delegate object ConstructorDelegate(params object[] args);
|
|
|
|
// Token: 0x020002EA RID: 746
|
|
// (Invoke) Token: 0x060030E4 RID: 12516
|
|
public delegate TValue ThreadSafeDictionaryValueFactory<TKey, TValue>(TKey key);
|
|
|
|
// Token: 0x020002EB RID: 747
|
|
public sealed class ThreadSafeDictionary<TKey, TValue> : IDictionary<TKey, TValue>, ICollection<KeyValuePair<TKey, TValue>>, IEnumerable<KeyValuePair<TKey, TValue>>, IEnumerable
|
|
{
|
|
// Token: 0x060030E7 RID: 12519 RVA: 0x000491F0 File Offset: 0x000473F0
|
|
public ThreadSafeDictionary(ReflectionUtils.ThreadSafeDictionaryValueFactory<TKey, TValue> valueFactory)
|
|
{
|
|
this._valueFactory = valueFactory;
|
|
}
|
|
|
|
// Token: 0x060030E8 RID: 12520 RVA: 0x0004920C File Offset: 0x0004740C
|
|
private TValue Get(TKey key)
|
|
{
|
|
TValue tvalue;
|
|
TValue tvalue2;
|
|
if (this._dictionary == null)
|
|
{
|
|
tvalue = this.AddValue(key);
|
|
}
|
|
else if (!this._dictionary.TryGetValue(key, out tvalue2))
|
|
{
|
|
tvalue = this.AddValue(key);
|
|
}
|
|
else
|
|
{
|
|
tvalue = tvalue2;
|
|
}
|
|
return tvalue;
|
|
}
|
|
|
|
// Token: 0x060030E9 RID: 12521 RVA: 0x0004925C File Offset: 0x0004745C
|
|
private TValue AddValue(TKey key)
|
|
{
|
|
TValue tvalue = this._valueFactory(key);
|
|
object @lock = this._lock;
|
|
lock (@lock)
|
|
{
|
|
if (this._dictionary == null)
|
|
{
|
|
this._dictionary = new Dictionary<TKey, TValue>();
|
|
this._dictionary[key] = tvalue;
|
|
}
|
|
else
|
|
{
|
|
TValue tvalue2;
|
|
if (this._dictionary.TryGetValue(key, out tvalue2))
|
|
{
|
|
return tvalue2;
|
|
}
|
|
Dictionary<TKey, TValue> dictionary = new Dictionary<TKey, TValue>(this._dictionary);
|
|
dictionary[key] = tvalue;
|
|
this._dictionary = dictionary;
|
|
}
|
|
}
|
|
return tvalue;
|
|
}
|
|
|
|
// Token: 0x060030EA RID: 12522 RVA: 0x00049310 File Offset: 0x00047510
|
|
public void Add(TKey key, TValue value)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
// Token: 0x060030EB RID: 12523 RVA: 0x00049318 File Offset: 0x00047518
|
|
public bool ContainsKey(TKey key)
|
|
{
|
|
return this._dictionary.ContainsKey(key);
|
|
}
|
|
|
|
// Token: 0x17000B07 RID: 2823
|
|
// (get) Token: 0x060030EC RID: 12524 RVA: 0x0004933C File Offset: 0x0004753C
|
|
public ICollection<TKey> Keys
|
|
{
|
|
get
|
|
{
|
|
return this._dictionary.Keys;
|
|
}
|
|
}
|
|
|
|
// Token: 0x060030ED RID: 12525 RVA: 0x0004935C File Offset: 0x0004755C
|
|
public bool Remove(TKey key)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
// Token: 0x060030EE RID: 12526 RVA: 0x00049364 File Offset: 0x00047564
|
|
public bool TryGetValue(TKey key, out TValue value)
|
|
{
|
|
value = this[key];
|
|
return true;
|
|
}
|
|
|
|
// Token: 0x17000B08 RID: 2824
|
|
// (get) Token: 0x060030EF RID: 12527 RVA: 0x00049388 File Offset: 0x00047588
|
|
public ICollection<TValue> Values
|
|
{
|
|
get
|
|
{
|
|
return this._dictionary.Values;
|
|
}
|
|
}
|
|
|
|
// Token: 0x17000B09 RID: 2825
|
|
public TValue this[TKey key]
|
|
{
|
|
get
|
|
{
|
|
return this.Get(key);
|
|
}
|
|
set
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
}
|
|
|
|
// Token: 0x060030F2 RID: 12530 RVA: 0x000493CC File Offset: 0x000475CC
|
|
public void Add(KeyValuePair<TKey, TValue> item)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
// Token: 0x060030F3 RID: 12531 RVA: 0x000493D4 File Offset: 0x000475D4
|
|
public void Clear()
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
// Token: 0x060030F4 RID: 12532 RVA: 0x000493DC File Offset: 0x000475DC
|
|
public bool Contains(KeyValuePair<TKey, TValue> item)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
// Token: 0x060030F5 RID: 12533 RVA: 0x000493E4 File Offset: 0x000475E4
|
|
public void CopyTo(KeyValuePair<TKey, TValue>[] array, int arrayIndex)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
// Token: 0x17000B0A RID: 2826
|
|
// (get) Token: 0x060030F6 RID: 12534 RVA: 0x000493EC File Offset: 0x000475EC
|
|
public int Count
|
|
{
|
|
get
|
|
{
|
|
return this._dictionary.Count;
|
|
}
|
|
}
|
|
|
|
// Token: 0x17000B0B RID: 2827
|
|
// (get) Token: 0x060030F7 RID: 12535 RVA: 0x0004940C File Offset: 0x0004760C
|
|
public bool IsReadOnly
|
|
{
|
|
get
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
}
|
|
|
|
// Token: 0x060030F8 RID: 12536 RVA: 0x00049414 File Offset: 0x00047614
|
|
public bool Remove(KeyValuePair<TKey, TValue> item)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
// Token: 0x060030F9 RID: 12537 RVA: 0x0004941C File Offset: 0x0004761C
|
|
public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator()
|
|
{
|
|
return this._dictionary.GetEnumerator();
|
|
}
|
|
|
|
// Token: 0x060030FA RID: 12538 RVA: 0x00049444 File Offset: 0x00047644
|
|
IEnumerator IEnumerable.GetEnumerator()
|
|
{
|
|
return this._dictionary.GetEnumerator();
|
|
}
|
|
|
|
// Token: 0x040009A7 RID: 2471
|
|
private readonly object _lock = new object();
|
|
|
|
// Token: 0x040009A8 RID: 2472
|
|
private readonly ReflectionUtils.ThreadSafeDictionaryValueFactory<TKey, TValue> _valueFactory;
|
|
|
|
// Token: 0x040009A9 RID: 2473
|
|
private Dictionary<TKey, TValue> _dictionary;
|
|
}
|
|
}
|
|
}
|