private void GenerateExpression() { //TODO: Enhance the type infering logic if (ExpressionType == null) { // Get the variables in scope List <ModelItem> declaredVariables = CSharpExpressionHelper.GetVariablesInScope(OwnerActivity); if (declaredVariables.Count > 0) { InferredType = ((LocationReference)(declaredVariables[0].GetCurrentValue())).Type; } } Type resultType = ExpressionType != null ? ExpressionType : InferredType; ////This could happen when: ////1) No ExpressionType is specified and ////2) The expression is invalid so that the inferred type equals to null if (resultType == null) { resultType = typeof(object); } // If the text is null we don't need to bother generating the expression (this would be the case the // first time you enter an ETB. We still need to generate the expression when it is EMPTY however - otherwise // the case where you had an expression (valid or invalid), then deleted the whole thing will not be evaluated. if (Text != null) { using (ModelEditingScope scope = OwnerActivity.BeginEdit("Property Change")) if (OwnerActivity != null) { EditingState = EditingState.Validating; // we set the expression to null // a) when the expressionText is empty AND it's a reference expression or // b) when the expressionText is empty AND the DefaultValue property is null if (Text.Length == 0 && (UseLocationExpression || (DefaultValue == null))) { Expression = null; } else { if (Text.Length == 0) { Text = DefaultValue; } ModelTreeManager modelTreeManager = Context.Services.GetService <ModelTreeManager>(); ActivityWithResult newExpression = CSharpExpressionHelper.CreateExpressionFromString(Text, UseLocationExpression, resultType); ModelItem expressionItem = modelTreeManager.CreateModelItem(null, newExpression); Expression = expressionItem; } scope.Complete(); } } }