Beispiel #1
0
        /// <summary>
        /// Initializes a new instance of <see cref="Binder"/>.
        /// </summary>
        /// <param name="target"> The target object</param>
        /// <param name="expression"> 
        /// The expression string.
        /// The format of the expression must be one of the following:
        /// <list type="number">
        ///     <item>
        ///         <term>"."</term> 
        ///         <description>
        ///             The value will be the DataContext itself.
        ///         </description>
        ///     </item>
        ///     <item>
        ///         <term>"Foo"</term> 
        ///         <description>
        ///             The value will be from <code>DataContext.Foo</code>. 
        ///         </description>
        ///     </item>
        ///     <item>
        ///         <term>"Foo[5].Bar"</term> 
        ///         <description>
        ///             The value will be from <code>DataContext.Foo[5].Bar</code>. 
        ///         </description>
        ///     </item>
        ///     <item>
        ///         <term>"Foo.Bar[\"baz\"].ToBaz()"</term> 
        ///         <description>
        ///             The value will be from <code>DataContext.Foo.Bar["baz"].ToBaz()</code>. 
        ///         </description>
        ///     </item>
        /// </list>
        /// </param>
        /// <param name="ignoreOnError">
        /// Determines whether missing properties on the context should
        /// throw exception or ignore.
        /// </param>
        /// <exception cref="ArgumentException"> The expression is empty</exception>
        /// <exception cref="ArgumentNullException"> expression is null</exception>
        public Binder(HierarchicalObject target, string expression, bool ignoreOnError)
        {
            _target = target;
            _ignoreOnError = ignoreOnError;

            if (expression == null)
                throw new ArgumentNullException(nameof(expression));

            if (string.IsNullOrWhiteSpace(expression))
                throw new ArgumentException($"the provided {nameof(expression)} is empty.", nameof(expression));

            // Trim the expression
            Expression = expression.Trim();

            // Single dot case
            if (Expression == ".")
            {
                // The contex itself.
                Expression = "__";
            }
            else
            {
                // Members of context otherwise.
                Expression = "__." + Expression;
            }
        }
 /// <summary>
 /// Initializes a new instance of <see cref="BindingExceprtion"/>.
 /// </summary>
 internal BindingTypeMismatchExceprtion(string message,
     Exception innerException,
     HierarchicalObject target,
     string expression, Type evaluationType, Type propertyType)
     : base(message, innerException, target, expression)
 {
     EvaluationType = evaluationType;
     PropertyType = propertyType;
 }
Beispiel #3
0
 /// <summary>
 /// Initializes a new instance of <see cref="BindingExceprtion"/>.
 /// </summary>
 internal BindingExceprtion(string message,
     Exception innerException,
     HierarchicalObject target,
     string expression)
     : base(message, innerException)
 {
     Target = target;
     Expression = expression;
 }