示例#1
0
        internal PropertyRedirection(PropertyInfo original, PropertyInfo replacement, bool start = false)
        {
            Original    = original;
            Replacement = replacement;

            if (original.GetMethod != null)
            {
                if (replacement.GetMethod == null)
                {
                    throw new ArgumentException("A get method must be defined.", nameof(replacement));
                }

                GetRedirection = new MethodRedirection(original.GetMethod, replacement.GetMethod, start);
            }

            if (original.SetMethod != null)
            {
                if (replacement.SetMethod == null)
                {
                    throw new ArgumentException("A set method must be defined.", nameof(replacement));
                }

                SetRedirection = new MethodRedirection(original.SetMethod, replacement.SetMethod, start);
            }
        }
示例#2
0
        internal EventRedirection(EventInfo original, EventInfo replacement, bool start = false)
        {
            Original    = original;
            Replacement = replacement;

            if (original.AddMethod != null)
            {
                if (replacement.AddMethod == null)
                {
                    throw new ArgumentException("An add method must be defined.", nameof(replacement));
                }

                AddRedirection = new MethodRedirection(original.AddMethod, replacement.AddMethod, start);
            }

            if (original.RemoveMethod != null)
            {
                if (replacement.RemoveMethod == null)
                {
                    throw new ArgumentException("A remove method must be defined.", nameof(replacement));
                }

                RemoveRedirection = new MethodRedirection(original.RemoveMethod, replacement.RemoveMethod, start);
            }

            if (original.RaiseMethod != null)
            {
                if (replacement.RaiseMethod == null)
                {
                    throw new ArgumentException("A raise method must be defined.", nameof(replacement));
                }

                RaiseRedirection = new MethodRedirection(original.RaiseMethod, replacement.RaiseMethod, start);
            }
        }
示例#3
0
        internal ObservableRedirection(int id, MethodRedirection redirection)
        {
            UnderlyingRedirection = redirection;
            Observers             = new List <IObserver <RedirectionContext> >();
            Key = id;

            ObservingRedirections.Add(id, this);
        }
示例#4
0
        /// <summary>
        ///   Returns an observable that allows observing the specified <paramref name="method"/>,
        ///   and hooking its calls, optionally modifying its return type.
        /// </summary>
        public static ObservableRedirection Observe(MethodBase method)
        {
            if (method == null)
            {
                throw new ArgumentNullException(nameof(method));
            }

            MethodRedirection redirection = CreateDynamicRedirection(method, out int id);

            return(new ObservableRedirection(id, redirection));
        }