Пример #1
0
        /// <summary>
        ///     Resolves the expression.
        /// </summary>
        /// <param name="expression">The expression.</param>
        /// <returns>System.Object.</returns>
        public object ResolveExpression(string expression)
        {
            if (string.IsNullOrWhiteSpace(expression))
            {
                return(null);
            }

            if (expression == "ClassName" || expression == "ClassType")
            {
                return(ClassType);
            }

            if (expression.Substring(0, 1).IsNumeric())
            {
                return(null);
            }

            object o = null;

            try
            {
                o = SpringExpression.GetValue(this, expression);
            }
            catch (NullValueInNestedPathException) // this is okay
            {
            }

            // ok, return what we've got
            return(o);
        }
Пример #2
0
        /// <summary>
        ///     Sets the value, swallowing any exceptions.
        /// </summary>
        /// <param name="expression">The expression.</param>
        /// <param name="newValue">The new value.</param>
        /// <returns>True if value was set successfully</returns>
        /// <exception cref="SDKException">Unable to add type '{0}' to a MemberSuite object - it cannot be serialized.</exception>
        public bool SetValue(string expression, object newValue)
        {
            if (newValue == DBNull.Value)
            {
                newValue = null;
            }

            if (!CanAdd(newValue))
            {
                throw new SDKException("Unable to add type '{0}' to a MemberSuite object - it cannot be serialized.",
                                       newValue.GetType());
            }

            if (string.IsNullOrEmpty(expression))
            {
                return(false);
            }

            // optimization - Parse is expensive, let's avoid it if we can
            if (
                !Regex.IsMatch(expression, RegularExpressions.CharactersThatNecessitateSpringRegex,
                               RegexOptions.Compiled))
            {
                Fields[expression] = newValue;
                return(true);
            }


            // get the expression
            try
            {
                var expr = SpringExpression.GetExpressionFor(expression);
                expr.SetValue(this, Fields, newValue);
                return(true);
            }
            catch
            {
                return(false);
            }
        }