コード例 #1
0
        /// <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);
        }
コード例 #2
0
 private bool IsIncompatibleWith(PropertyInfoElement propertyInfoElement)
 {
     return(!propertyInfoElement
            .PropertyInfo
            .DeclaringType
            .IsInstanceOfType(this.target));
 }
コード例 #3
0
 private string CreateIncompatibilityMessageFor(
     PropertyInfoElement propertyInfoElement)
 {
     return(string.Format(
                CultureInfo.CurrentCulture,
                "Property '{0}' defined on type '{1}' is not a property on the target object, which is of type '{2}'.",
                propertyInfoElement.PropertyInfo.Name,
                propertyInfoElement.PropertyInfo.DeclaringType,
                this.target.GetType()));
 }
コード例 #4
0
        /// <summary>
        /// Visits the <see cref="FieldInfoElement"/> and collects the value for this
        /// field from the <see cref="Target"/> 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>
        public override IReflectionVisitor <IEnumerable <object> > Visit(
            PropertyInfoElement propertyInfoElement)
        {
            if (propertyInfoElement == null)
            {
                throw new ArgumentNullException("propertyInfoElement");
            }
            if (this.IsIncompatibleWith(propertyInfoElement))
            {
                throw new ArgumentException(
                          this.CreateIncompatibilityMessageFor(propertyInfoElement),
                          "propertyInfoElement");
            }

            var value =
                propertyInfoElement.PropertyInfo.GetValue(this.target, null);

            return(new ValueCollectingVisitor(
                       this.target,
                       this.values.Concat(new[] { value }).ToArray()));
        }