System.ComponentModel.ScriptExpression.Parse C# (CSharp) Method

Parse() public static method

Parses text representing a script expression into a ScriptExpression instance.
public static Parse ( string expression ) : ScriptExpression
expression string The text to parse.
return ScriptExpression
        public static ScriptExpression Parse(string expression)
        {
            if (String.IsNullOrEmpty(expression)) {
                throw new ArgumentNullException("expression");
            }

            string[] scriptParts = expression.Split('=');
            if ((scriptParts != null) && (scriptParts.Length == 1)) {
                IValueExpression rhs = ParseExpression(scriptParts[0].Trim(), /* allowMethod */ true);
                if (rhs != null) {
                    return new ScriptExpression(expression, rhs);
                }
            }
            else if (scriptParts.Length == 2) {
                IValueExpression rhs = ParseExpression(scriptParts[1].Trim(), /* allowMethod */ true);
                IValueExpression lhs = ParseExpression(scriptParts[0].Trim(), /* allowMethod */ false);

                if ((rhs != null) && (lhs != null) && (lhs is PropertyAccessExpression)) {
                    if (((PropertyAccessExpression)lhs).IsValidSetterExpression) {
                        return new ScriptExpression(expression, rhs, lhs);
                    }
                }
            }

            return null;
        }