/// <summary>
        /// Allows an <see cref="PropertyInfoElement"/> to be visited.
        /// This method is called when the element accepts this visitor
        /// instance.
        /// </summary>
        /// <param name="propertyInfoElement">
        /// The <see cref="PropertyInfoElement"/> being visited.
        /// </param>
        /// <returns>
        /// A <see cref="IReflectionVisitor{T}" /> instance which can be used
        /// to continue the visiting process with potentially updated
        /// observations.
        /// </returns>
        /// <remarks>
        /// <para>
        /// This implementation relays the two <see cref="MethodInfoElement"/> instances
        /// from the getter and setter of the <see cref="PropertyInfoElement"/> parameter,
        /// to <see cref="Visit(MethodInfoElement)"/>,
        /// but since the method is virtual, child classes can override it.
        /// </para>
        /// </remarks>
        public virtual IReflectionVisitor <T> Visit(
            PropertyInfoElement propertyInfoElement)
        {
            if (propertyInfoElement == null)
            {
                throw new ArgumentNullException("propertyInfoElement");
            }

            var getMethodInfoElement = propertyInfoElement.GetGetMethodInfoElement();
            var setMethodInfoElement = propertyInfoElement.GetSetMethodInfoElement();

            IReflectionVisitor <T> visitor = this;

            if (getMethodInfoElement != null)
            {
                visitor = visitor.Visit(getMethodInfoElement);
            }

            if (setMethodInfoElement != null)
            {
                visitor = visitor.Visit(setMethodInfoElement);
            }

            return(visitor);
        }
        /// <summary>
        /// Allows an <see cref="EventInfoElement"/> to be visited. This method
        /// is called when the element accepts this visitor instance.
        /// </summary>
        /// <param name="eventInfoElement">
        /// The <see cref="EventInfoElement"/> being visited.
        /// </param>
        /// <returns>
        /// A <see cref="IReflectionVisitor{T}" /> instance which can be used
        /// to continue the visiting process with potentially updated
        /// observations.
        /// </returns>
        /// <remarks>
        /// <para>
        /// This implementation simply returns
        /// <paramref name="eventInfoElement" /> without doing anything, but
        /// since the method is virtual, child classes can override it.
        /// </para>
        /// </remarks>
        public virtual IReflectionVisitor <T> Visit(
            EventInfoElement eventInfoElement)
        {
            if (eventInfoElement == null)
            {
                throw new ArgumentNullException("eventInfoElement");
            }

            IReflectionVisitor <T> visitor = this;

            visitor = visitor.Visit(eventInfoElement.GetAddMethodInfoElement());
            visitor = visitor.Visit(eventInfoElement.GetRemoveMethodInfoElement());
            return(visitor);
        }
Example #3
0
 /// <summary>
 /// Accepts the provided <see cref="IReflectionVisitor{T}"/>, by calling the
 /// appropriate strongly-typed <see cref="IReflectionVisitor{T}.Visit(PropertyInfoElement)"/>
 /// method on the visitor.
 /// </summary>
 /// <typeparam name="T">The type of observation or result which the
 /// <see cref="IReflectionVisitor{T}"/> instance produces when visiting nodes.</typeparam>
 /// <param name="visitor">The <see cref="IReflectionVisitor{T}"/> instance.</param>
 /// <returns>A (potentially) new <see cref="IReflectionVisitor{T}"/> instance which can be
 /// used to continue the visiting process with potentially updated observations.</returns>
 public IReflectionVisitor <T> Accept <T>(IReflectionVisitor <T> visitor)
 {
     if (visitor == null)
     {
         throw new ArgumentNullException("visitor");
     }
     return(visitor.Visit(this));
 }