Microsoft.R.Core.AST.StatementExtensions.GetVariableOrFunctionDefinition C# (CSharp) Method

GetVariableOrFunctionDefinition() public static method

Given expression statement determines if it defines a function and if so, returns the function definition and the variable it is assigned to.
public static GetVariableOrFunctionDefinition ( this es, Variable &v ) : IFunctionDefinition
es this
v Microsoft.R.Core.AST.Variables.Variable
return IFunctionDefinition
        public static IFunctionDefinition GetVariableOrFunctionDefinition(this IExpressionStatement es, out Variable v) {
            v = null;
            if (es == null || es.Expression == null) {
                return null;
            }

            // Tree:
            //       <-
            //    x      function(a)
            //
            //
            var c = es.Expression.Children;
            if (c.Count == 1) {
                var op = c[0] as IOperator;
                if (op != null) {
                    if (op.OperatorType == OperatorType.LeftAssign || op.OperatorType == OperatorType.Equals) {
                        v = op.LeftOperand as Variable;
                        if (v != null) {
                            return op.RightOperand as IFunctionDefinition;
                        }
                    }
                    else if (op.OperatorType == OperatorType.RightAssign) {
                        v = op.RightOperand as Variable;
                    }
                }
            }
            return null;
        }
    }