コード例 #1
0
        public ref TRefReturn GetProperty <TRefReturn>(string name)
        {
            return(ref ProfilerInterceptor.GuardInternal((target, arguments) =>
            {
                var prop = MockingUtil.ResolveProperty(this.type, name, false, null, this.instance != null);
                var method = prop.GetGetMethod(true);

                ProfilerInterceptor.RefReturn <TRefReturn> @delegate =
                    MockingUtil.CreateDynamicMethodInvoker <TRefReturn>(target, method, arguments);

                return ref ProfilerInterceptor.GuardExternal(@delegate, target, arguments);
            }, this.instance, MockingUtil.NoObjects));
        }
コード例 #2
0
        public ref TRefReturn CallMethod <TRefReturn>(string name, params object[] args)
        {
            return(ref ProfilerInterceptor.GuardInternal((target, arguments) =>
            {
                arguments = arguments ?? MockingUtil.NoObjects;
                var candidates = type.GetAllMethods()
                                 .Where(m => m.Name == name && MockingUtil.CanCall(m, this.instance != null))
                                 .Select(m => MockingUtil.TrySpecializeGenericMethod(m, arguments.Select(a => a != null ? a.GetType() : null).ToArray()) ?? m)
                                 .ToArray();
                object state;
                var method = MockingUtil.BindToMethod(MockingUtil.AllMembers, candidates, ref arguments, null, null, null, out state);

                ProfilerInterceptor.RefReturn <TRefReturn> @delegate =
                    MockingUtil.CreateDynamicMethodInvoker <TRefReturn>(target, method as MethodInfo, arguments);

                return ref ProfilerInterceptor.GuardExternal(@delegate, target, arguments);
            }, this.instance, args ?? MockingUtil.NoObjects));
        }