public static MethodBehaviors BuildBehaviors(Type proxyType, MethodBehaviors behaviorOverrides, List <MethodInfo> methodsList)
        {
            if (behaviorOverrides == null)
            {
                behaviorOverrides = new MethodBehaviors();
            }
            List <MethodInfo> methods = ProxyMethodsConverter.GetMethods(proxyType, methodsList);

            // Copy received ones so that we don't modify original argument value.
            MethodBehaviors behaviors = new MethodBehaviors();

            if (behaviorOverrides != null)
            {
                foreach (MethodBehavior behavior in behaviorOverrides)
                {
                    behaviors.Add(behavior);
                    MethodBehaviorHelper.RemoveMethod(methods, behavior.Method);
                }
            }

            // Add the remaining ones as not-overriden behaviors.
            foreach (MethodInfo method in methods)
            {
                behaviors.Add(new MethodBehavior(method, false));
            }

            return(behaviors);
        }
示例#2
0
        public void ShouldnotRemoveUnequalMethod()
        {
            List <MethodInfo> agentMethods = new List <MethodInfo>(typeof(MockProxyAgent).GetMethods());
            MethodInfo        proxyMethod  = typeof(MockProxy).GetMethod("NotAgentedMethod", new Type[] {});
            int methodsCount = agentMethods.Count;

            MethodBehaviorHelper.RemoveMethod(agentMethods, proxyMethod);

            Assert.IsNotNull(proxyMethod);
            Assert.AreNotEqual(0, methodsCount);
            Assert.AreEqual(methodsCount, agentMethods.Count);
        }
示例#3
0
        public void ShouldRemoveEqualNotSameMethod()
        {
            List <MethodInfo> agentMethods = new List <MethodInfo>(typeof(MockProxyAgent).GetMethods());
            MethodInfo        proxyMethod  = typeof(MockProxy).GetMethod("HelloWorld", new Type[] { typeof(string) });
            bool containsTargetMethod      = agentMethods.Contains(proxyMethod);
            int  methodsCount = agentMethods.Count;

            MethodBehaviorHelper.RemoveMethod(agentMethods, proxyMethod);

            Assert.IsNotNull(proxyMethod);
            Assert.AreNotEqual(0, methodsCount);
            Assert.IsFalse(containsTargetMethod);
            Assert.AreEqual(methodsCount - 1, agentMethods.Count);
        }