Exemplo n.º 1
0
        private static string GetEntityTypeFromKey(string key, out string typeName, ref Type type, out string asmName, out bool isEntityType, out string redisKey)
        {
            int index = key.IndexOf(',');
            var arr   = (index > -1 ? key.Substring(0, index) : key).Split('_');

            typeName = arr[0];
            asmName  = index == -1 ? "" : key.Substring(index + 1, key.Length - index - 1);
            string persionKey = string.Empty;
            string entityKey  = string.Empty;

            if (arr.Length > 1)
            {
                entityKey = arr[1];
                var tempArr = entityKey.Split('|');
                if (tempArr.Length > 1)
                {
                    persionKey = tempArr[0];
                    entityKey  = tempArr[1];
                }
            }
            isEntityType = false;
            if (string.IsNullOrEmpty(persionKey))
            {
                isEntityType = true;
                redisKey     = string.Format("{0}_{1}", RedisConnectionPool.EncodeTypeName(typeName), entityKey);
            }
            else
            {
                //私有类型
                redisKey = string.Format("{0}_{1}", RedisConnectionPool.EncodeTypeName(typeName), persionKey);
            }
            string formatString = entityTypeNameFormat;

            if (isEntityType)
            {
                formatString = "{0},{1}";
            }
            if (type == null)
            {
                string entityTypeName = RedisConnectionPool.DecodeTypeName(typeName);
                type = Type.GetType(string.Format(formatString, entityTypeName, asmName), false, true);
                if (Equals(type, null))
                {
                    var enitityAsm = ScriptEngines.GetEntityAssembly();
                    if (enitityAsm != null)
                    {
                        asmName = enitityAsm.GetName().Name;
                        type    = Type.GetType(string.Format(formatString, entityTypeName, asmName), false, true);
                        if (Equals(type, null))
                        {
                            //调试模式下type为空处理
                            type = enitityAsm.GetType(entityTypeName, false, true);
                        }
                    }
                }
            }
            return(entityKey);
        }