コード例 #1
0
        internal static Boolean CanCreateInterfaceProxy(Type targetType, Type interfaceType)
        {
            ObservedType oType = GetObservedType(targetType);

            if (oType == null)
            {
                return(false);
            }
            return(oType.CanCreateInterfaceProxy(interfaceType));
        }
コード例 #2
0
        internal static Boolean CanCreateSubProxy(Type targetType)
        {
            ObservedType oType = GetObservedType(targetType);

            if (oType == null)
            {
                return(false);
            }
            return(oType.CanCreateSubProxy());
        }
コード例 #3
0
 private static bool hasAddMethod(ObservedType ot, MethodInfo method)
 {
     foreach (ObservedMethod x in ot.MethodList)
     {
         if (x.Method == method)
         {
             return(true);
         }
     }
     return(false);
 }
コード例 #4
0
        private static void addTypeSingle(Dictionary <Type, ObservedType> results, MethodObserver obj, Type t, MethodInfo method)
        {
            ObservedType oType;

            results.TryGetValue(t, out oType);
            if (oType == null)
            {
                oType = new ObservedType();
            }

            oType.Type = t;
            populateMethodList(oType, obj, method);

            results[t] = oType;
        }
コード例 #5
0
        private static void populateMethodList(ObservedType oType, MethodObserver obj, MethodInfo method)
        {
            if (oType.MethodList == null)
            {
                oType.MethodList = new List <ObservedMethod>();
            }

            if (hasAddMethod(oType, method))
            {
                oType.MethodList = addObserverToMethodList(oType.MethodList, method, obj);
            }
            else
            {
                ObservedMethod om = addNewObserverMethod(obj, method);
                om.ObservedType = oType;
                oType.MethodList.Add(om);
            }
        }
コード例 #6
0
        /// <summary>
        /// 获取某方法的监控器
        /// </summary>
        /// <param name="t"></param>
        /// <param name="methodName"></param>
        /// <returns></returns>
        public static List <MethodObserver> GetMethodObservers(Type t, String methodName)
        {
            ObservedType oType = GetObservedType(t);

            if (oType == null)
            {
                return(new List <MethodObserver>());
            }

            List <ObservedMethod> list = oType.MethodList;

            foreach (ObservedMethod x in list)
            {
                if (x.Method.Name == methodName)
                {
                    return(x.Observer);
                }
            }

            return(null);
        }
コード例 #7
0
        /// <summary>
        /// 根据类型创建它的代理类。如果代理不存在,返回 null。
        /// 如果方法非虚,不可以创建,那么抛出异常。
        /// </summary>
        /// <param name="targetType"></param>
        /// <returns></returns>
        public static Object CreateProxyBySub(Type targetType)
        {
            if (targetType == null)
            {
                throw new NullReferenceException("targetType");
            }

            ObservedType oType = GetObservedType(targetType);

            if (oType == null)
            {
                return(null);
            }
            if (oType.CanCreateSubProxy() == false)
            {
                String exMsg = "method not virtual. type=" + targetType.FullName + ", method=" + oType.GetNotVirtualMethodString();
                logger.Error(exMsg);
                throw new MethodNotVirtualException(exMsg);
            }

            return(createProxyBySub(targetType));
        }