Ejemplo n.º 1
0
 /// <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);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// 检测链接
        /// </summary>
        /// <param name="assembly">程序集</param>
        internal unsafe static void CheckConnection(Assembly assembly)
        {
            bool   isAssembly;
            string assemblyName = assembly.FullName;

            fixed(char *nameFixed = assemblyName)
            {
                char *splitIndex = unsafer.String.FindAscii(nameFixed, nameFixed + assemblyName.Length, checkConnectionAssemblyNameMap.Map);

                isAssembly = splitIndex == null || !checkConnectionAssemblyNames.Contains(assemblyName.Substring(0, (int)(splitIndex - nameFixed)));
            }

            if (isAssembly)
            {
                Type currentType = null;
                try
                {
                    foreach (Type type in assembly.GetTypes())
                    {
                        if (type.IsClass && !type.IsAbstract && !type.IsGenericType && type.IsVisible)
                        {
                            fastCSharp.emit.sqlTable sqlTable = fastCSharp.code.typeAttribute.GetAttribute <fastCSharp.emit.sqlTable>(type, false, true);
                            if (sqlTable != null && Array.IndexOf(fastCSharp.config.sql.Default.CheckConnection, sqlTable.ConnectionType) != -1)
                            {
                                Type modelType;
                                fastCSharp.code.cSharp.sqlModel sqlModel = fastCSharp.code.cSharp.dataModel.GetModelType <fastCSharp.code.cSharp.sqlModel>(type, out modelType);
                                checkSqlTable(currentType = type, modelType ?? type, sqlModel, sqlTable);
                            }
                        }
                    }
                }
                catch (Exception error)
                {
                    fastCSharp.log.Error.Add(error, currentType.fullName(), true);
                }
                finally
                {
                    EventWaitHandle wait = null;
                    if (checkAssemblyNames.Set(assemblyName, null, out wait))
                    {
                        wait.Set();
                        wait.Close();
                    }
                }
            }
        }
Ejemplo n.º 3
0
 /// <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);
 }
Ejemplo n.º 4
0
        /// <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);
        }
Ejemplo n.º 5
0
            /// <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);
            }
Ejemplo n.º 6
0
        /// <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);
        }
Ejemplo n.º 7
0
        /// <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);
        }
Ejemplo n.º 8
0
        /// <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);
        }
Ejemplo n.º 9
0
        /// <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);
        }
Ejemplo n.º 10
0
        /// <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);
        }
Ejemplo n.º 11
0
        /// <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);
        }
Ejemplo n.º 12
0
        /// <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);
        }
Ejemplo n.º 13
0
        /// <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);
        }
Ejemplo n.º 14
0
            /// <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);
            }
Ejemplo n.º 15
0
        /// <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);
        }
Ejemplo n.º 16
0
        /// <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);
        }
Ejemplo n.º 17
0
 private static void loadAssembly(Assembly assembly)
 {
     nameCache.Set(assembly.FullName, assembly);
 }
Ejemplo n.º 18
0
 static assembly()
 {
     nameCache = new interlocked.dictionary<hashString,Assembly>(dictionary.CreateHashString<Assembly>());
     AppDomain.CurrentDomain.AssemblyLoad += loadAssembly;
     foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies()) nameCache.Set(assembly.FullName, assembly);
 }