Пример #1
0
        /// <summary>
        /// Poke the given value into the given target indicated by our AspectName.
        /// </summary>
        /// <remarks>
        /// <para>
        /// If the AspectName is a dotted path, all the selectors bar the last
        /// are used to find the object that should be updated, and the last
        /// selector is used as the property to update on that object.
        /// </para>
        /// <para>
        /// So, if 'target' is a Person and the AspectName is "HomeAddress.Postcode",
        /// this method will first fetch "HomeAddress" property, and then try to set the
        /// "Postcode" property on the home address object.
        /// </para>
        /// </remarks>
        /// <param name="target">The object that will be poked</param>
        /// <param name="value">The value that will be poked into the target</param>
        /// <returns>bool indicating whether the put worked</returns>
        public bool PutValue(Object target, Object value)
        {
            if (this.Parts.Count == 0)
            {
                return(false);
            }

            SimpleMunger lastPart = this.Parts[this.Parts.Count - 1];

            if (this.Parts.Count > 1)
            {
                List <SimpleMunger> parts = new List <SimpleMunger>(this.Parts);
                parts.RemoveAt(parts.Count - 1);
                try {
                    target = this.EvaluateParts(target, parts);
                } catch (MungerException ex) {
                    this.ReportPutValueException(ex);
                    return(false);
                }
            }

            if (target != null)
            {
                try {
                    return(lastPart.PutValue(target, value));
                } catch (MungerException ex) {
                    this.ReportPutValueException(ex);
                }
            }

            return(false);
        }
Пример #2
0
 /// <summary>
 /// Create a MungerException
 /// </summary>
 /// <param name="munger"></param>
 /// <param name="target"></param>
 /// <param name="ex"></param>
 public MungerException(SimpleMunger munger, object target, Exception ex)
     : base("Munger failed", ex)
 {
     this.munger = munger;
     this.target = target;
 }