示例#1
0
        /// <summary>
        /// 获取成员变量对应属性的缓存信息
        /// </summary>
        /// <param name="type">JObject继承类的类型</param>
        /// <param name="isSet">是否为设置值</param>
        /// <param name="fieldName">java成员变量名称</param>
        /// <returns>缓存信息对象实例</returns>
        public static JCacheInfo GetCacheFieldParam(Type type, bool isSet, string fieldName)
        {
            PropertyInfo pinfo = null;
            MethodBase dotnetMethod = null;
            int iNext = 2;
            do
            {
                StackFrame frame = new StackFrame(iNext++, true);
                dotnetMethod = frame.GetMethod();
                if (dotnetMethod == null) break;
                if (!dotnetMethod.IsSpecialName) continue;
                if (!dotnetMethod.DeclaringType.IsSubclassOf(typeof(JObject))) continue;

                BindingFlags bindingFlags = !dotnetMethod.IsStatic ? BindingFlags.IgnoreCase | BindingFlags.Public : BindingFlags.IgnoreCase | BindingFlags.Static | BindingFlags.Public;
                type = dotnetMethod.DeclaringType;
                pinfo = type.GetProperty(fieldName);
                if (pinfo != null) break;
            }
            while (dotnetMethod != null);

            if (pinfo == null)
                throw new MethodAccessException("未找到调用链上的属性。");

            MethodInfo mi = (MethodInfo)dotnetMethod;
            bool isStatic = dotnetMethod.IsStatic;
            bool isVoid = mi.ReturnType == typeof(void);

            JCacheInfo jcacheInfo = new JCacheInfo { IsVoid = isVoid, IsStatic = isStatic, Name = fieldName };
            if (isSet)
                jcacheInfo.Params = mi.GetParameters().ToList();
            return jcacheInfo;
        }
示例#2
0
 /// <summary>
 /// 转换成 java 可用的参数对象
 /// </summary>
 /// <param name="info">java 缓存信息</param>
 /// <param name="values">参数值</param>
 /// <returns>java 可用的参数值列表</returns>
 public static IParamValue[] ConvertToJParams(JCacheInfo info, object[] values)
 {
     List<IParamValue> lstJPVs = new List<IParamValue>();
     int idx = 0;
     foreach (var pinfo in info.Params)
         lstJPVs.Add(JInvokeHelper.CreateJParamValue(pinfo/*pinfo.ParameterType*/, values[idx++]));
     return lstJPVs.ToArray();
 }
示例#3
0
 /// <summary>
 /// 添加缓存信息
 /// </summary>
 /// <param name="type">JObject继承类</param>
 /// <param name="cacheName">缓存的名称 key</param>
 /// <param name="value">缓存信息</param>
 public static void Add(Type type, string cacheName, JCacheInfo value)
 {
     if (!HasCache(type, cacheName))
     {
         if (!dicDatas.ContainsKey(type))
         {
             Dictionary<string, JCacheInfo> d = new Dictionary<string, JCacheInfo>();
             d.Add(cacheName, value);
             dicDatas.Add(type, d);
         }
         else
         {
             var d = dicDatas[type];
             d.Add(cacheName, value);
             dicDatas[type] = d;
         }
     }
     else
     {
         var d = dicDatas[type];
         d.Add(cacheName, value);
         dicDatas[type] = d;
     }
 }