/// <summary> /// 根据类型获取自定义属性函数信息集合 /// </summary> /// <param name="type">对象类型</param> /// <returns>自定义属性函数信息集合</returns> public static attributeMethod[] GetStatic(Type type) { attributeMethod[] values; if (staticMethods.TryGetValue(type, out values)) { return(values); } Monitor.Enter(createStaticLock); try { if (staticMethods.TryGetValue(type, out values)) { return(values); } subArray <attributeMethod> array = default(subArray <attributeMethod>); foreach (MethodInfo method in type.GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)) { object[] attributes = method.GetCustomAttributes(true); if (attributes.Length != 0) { array.Add(new attributeMethod { Method = method, attributes = attributes }); } } staticMethods.Set(type, values = array.ToArray()); } finally { Monitor.Exit(createStaticLock); } return(values); }
/// <summary> /// 根据类型获取自定义属性信息集合 /// </summary> /// <param name="type">对象类型</param> /// <returns>自定义属性信息集合</returns> private static object[] get(Type type) { object[] values; if (attributes.TryGetValue(type, out values)) { return(values); } attributes.Set(type, values = type.GetCustomAttributes(false)); return(values); }
/// <summary> /// 代码菜单 /// </summary> /// <param name="path"></param> /// <returns></returns> public static item Get(string file) { item item; if (!cache.TryGetValue(file, out item)) { FileInfo fileInfo = new FileInfo(file); cache.Set(file, item = fileInfo.Exists ? new item(fileInfo) : null); } return(item); }
/// <summary> /// 获取类型比较字段与委托调用 /// </summary> /// <param name="type"></param> /// <returns></returns> public static Func <object, object, bool> GetObjectEquals(Type type) { Func <object, object, bool> method; if (objectEquals.TryGetValue(type, out method)) { return(method); } objectEquals.Set(type, method = (Func <object, object, bool>)Delegate.CreateDelegate(typeof(Func <object, object, bool>), typeof(equals <>).MakeGenericType(type).GetMethod("objectEquals", BindingFlags.Static | BindingFlags.NonPublic))); return(method); }
/// <summary> /// 获取随机函数 /// </summary> /// <param name="type"></param> /// <returns></returns> internal static MethodInfo GetRandom(Type type) { MethodInfo method; if (randomMethods.TryGetValue(type, out method)) { return(method); } randomMethods.Set(type, method = randomMethod.MakeGenericMethod(type)); return(method); }
/// <summary> /// 获取模拟类型 /// </summary> /// <param name="type">数据类型</param> /// <returns></returns> internal static type GetType(Type type) { type mockType; if (types.TryGetValue(type, out mockType)) { return(mockType); } types.Set(type, mockType = (type)typeMethod.MakeGenericMethod(type).Invoke(null, null)); return(mockType); }
/// <summary> /// 获取模拟调用 /// </summary> /// <param name="type"></param> /// <returns></returns> internal static MethodInfo GetMock(Type type) { MethodInfo method; if (mockMethods.TryGetValue(type, out method)) { return(method); } mockMethods.Set(type, method = mockMethod.MakeGenericMethod(type)); return(method); }
/// <summary> /// 获取接口模拟包装 /// </summary> /// <param name="type"></param> /// <returns></returns> internal static MethodInfo GetInterface(Type type) { MethodInfo method; if (interfaceMethods.TryGetValue(type, out method)) { return(method); } interfaceMethods.Set(type, method = interfaceMethod.MakeGenericMethod(type)); return(method); }
/// <summary> /// 获取可空类型获取数据函数信息 /// </summary> /// <param name="type"></param> /// <returns>可空类型获取数据函数信息</returns> internal static MethodInfo GetNullableValue(Type type) { MethodInfo method; if (nullableValues.TryGetValue(type, out method)) { return(method); } method = type.GetProperty("Value", BindingFlags.Instance | BindingFlags.Public).GetGetMethod(); nullableValues.Set(type, method); return(method); }
/// <summary> /// 获取数值转换委托调用函数信息 /// </summary> /// <param name="type">数值类型</param> /// <returns>数值转换委托调用函数信息</returns> public static MethodInfo GetNumberToStringMethod(Type type) { MethodInfo method; if (numberToStringMethods.TryGetValue(type, out method)) { return(method); } method = typeof(fastCSharp.number).GetMethod("toString", BindingFlags.Static | BindingFlags.Public, null, new Type[] { type }, null); numberToStringMethods.Set(type, method); return(method); }
/// <summary> /// 获取SQL常量转换函数信息 /// </summary> /// <param name="type">数值类型</param> /// <returns>SQL常量转换函数信息</returns> internal static MethodInfo GetSqlConverterMethod(Type type) { MethodInfo method; if (sqlConverterMethods.TryGetValue(type, out method)) { return(method); } method = typeof(constantConverter).GetMethod("convertConstant", BindingFlags.Instance | BindingFlags.NonPublic, null, new Type[] { typeof(charStream), type }, null) ?? constantConverter.ConvertConstantStringMethod.MakeGenericMethod(type); sqlConverterMethods.Set(type, method); return(method); }
/// <summary> /// 获取类型比较字段与委托调用 /// </summary> /// <param name="type"></param> /// <returns></returns> private static keyValue <FieldInfo, MethodInfo> getEqualsFieldInvoke(Type type) { keyValue <FieldInfo, MethodInfo> fieldInvoke; if (equalsFieldInvokes.TryGetValue(type, out fieldInvoke)) { return(fieldInvoke); } fieldInvoke.Key = typeof(equals <>).MakeGenericType(type).GetField("Equals", BindingFlags.Static | BindingFlags.Public); fieldInvoke.Value = typeof(Func <, ,>).MakeGenericType(type, type, typeof(bool)).GetMethod("Invoke", BindingFlags.Instance | BindingFlags.Public, null, new Type[] { type, type }, null); equalsFieldInvokes.Set(type, fieldInvoke); return(fieldInvoke); }
/// <summary> /// 获取名称数据 /// </summary> /// <param name="name"></param> /// <returns></returns> public static unsafe char *GetNamePool(string name) { pointer pointer; if (namePools.TryGetValue(name, out pointer)) { return(pointer.Char); } char *value = pub.GetNamePool(name, 1, 1); *value = '&'; *(value + (1 + name.Length)) = '='; namePools.Set(name, new pointer(value)); return(value); }
/// <summary> /// 等待检测链接 /// </summary> /// <param name="assembly">程序集</param> public static void WaitCheckConnection(Assembly assembly) { if (assembly != null) { EventWaitHandle wait = null; hashString assemblyName = assembly.FullName; if (!checkAssemblyNames.TryGetValue(assemblyName, out wait)) { checkAssemblyNames.Set(assemblyName, wait = new EventWaitHandle(false, EventResetMode.ManualReset)); } if (wait != null) { wait.WaitOne(); } } }
/// <summary> /// 获取名称赋值数据 /// </summary> /// <param name="name"></param> /// <returns></returns> public static unsafe char *GetNameAssignmentPool(string name) { pointer pointer; if (nameAssignmentPools.TryGetValue(name, out pointer)) { return(pointer.Char); } char *value = namePool.Get(name, 0, 1); *(value + name.Length) = '='; nameAssignmentPools.Set(name, new pointer { Data = value }); return(value); }
/// <summary> /// 获取类型转换函数 /// </summary> /// <param name="fromType"></param> /// <param name="toType"></param> /// <returns></returns> internal static MethodInfo GetCastMethod(Type fromType, Type toType) { if (fromType == toType) { return(null); } #if NOJIT #else if (fromType == typeof(int)) { if (toType == typeof(uint)) { return(null); } } else if (fromType == typeof(long)) { if (toType == typeof(ulong)) { return(null); } } else if (fromType == typeof(byte)) { if (toType == typeof(sbyte)) { return(null); } } else if (fromType == typeof(short)) { if (toType == typeof(ushort)) { return(null); } } #endif castType castType = new castType { FromType = fromType, ToType = toType }; MethodInfo method; if (castMethods.TryGetValue(castType, out method)) { return(method); } #if NOJIT #else if (!toType.IsPrimitive) #endif { foreach (MethodInfo methodInfo in toType.GetMethods(BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public)) { if (methodInfo.ReturnType == toType && (methodInfo.Name == "op_Implicit" || methodInfo.Name == "op_Explicit") && methodInfo.GetParameters()[0].ParameterType == fromType) { method = methodInfo; break; } } //Type[] castParameterTypes = new Type[] { fromType }; //method = toType.GetMethod("op_Implicit", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public, null, castParameterTypes, null) // ?? toType.GetMethod("op_Explicit", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public, null, castParameterTypes, null); } #if NOJIT if (method == null) #else if (method == null && !fromType.IsPrimitive) #endif { foreach (MethodInfo methodInfo in fromType.GetMethods(BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public)) { if (methodInfo.ReturnType == toType && (methodInfo.Name == "op_Implicit" || methodInfo.Name == "op_Explicit") && methodInfo.GetParameters()[0].ParameterType == fromType) { method = methodInfo; break; } } } castMethods.Set(castType, method); return(method); }