public override bool TryInferReturnType(ActivityWithResult expression, EditingContext context, out Type returnType) { bool succeeded = false; Fx.Assert(expression.GetType().GetGenericTypeDefinition() == typeof(VisualBasicValue <>) || expression.GetType().GetGenericTypeDefinition() == typeof(VisualBasicReference <>), "VisualBasicExpressionMorphHelper should only apply to VB expression."); SourceExpressionException compileError; VisualBasicSettings settings; if (ExpressionHelper.IsGenericLocationExpressionType(expression)) { VisualBasicDesignerHelper.RecompileVisualBasicReference( expression, out returnType, out compileError, out settings); } else { VisualBasicDesignerHelper.RecompileVisualBasicValue( expression, out returnType, out compileError, out settings); } if (compileError == null) { succeeded = true; if (settings != null) { //merge with import designer foreach (VisualBasicImportReference reference in settings.ImportReferences) { ImportDesigner.AddImport(reference.Import, context); } } } return(succeeded); }
static SendReply CreateSendReply(ModelItem target, object context) { SendReply reply = null; ModelItem receive = (ModelItem)context; if (null != receive) { Receive receiveInstance = (Receive)receive.GetCurrentValue(); string name = null; //if no correlation is set - create one if (null == receiveInstance.CorrelatesWith) { Variable handleVariable = null; //first, look for nearest variable scope ModelItemCollection variableScope = VariableHelper.FindRootVariableScope(receive).GetVariableCollection(); if (null != variableScope) { ModelItemCollection correlations = receive.Properties["CorrelationInitializers"].Collection; bool hasRequestReplyHandle = false; foreach (ModelItem item in correlations) { if (item.ItemType.IsAssignableFrom(typeof(RequestReplyCorrelationInitializer))) { hasRequestReplyHandle = true; break; } } if (!hasRequestReplyHandle) { //create unique variable name name = variableScope.CreateUniqueVariableName("__handle", 1); //create variable handleVariable = Variable.Create(name, typeof(CorrelationHandle), VariableModifiers.None); //add it to the scope variableScope.Add(handleVariable); //setup correlation ImportDesigner.AddImport(CorrelationHandleTypeNamespace, receive.GetEditingContext()); VariableValue <CorrelationHandle> expression = new VariableValue <CorrelationHandle> { Variable = handleVariable }; InArgument <CorrelationHandle> handle = new InArgument <CorrelationHandle>(expression); correlations.Add(new RequestReplyCorrelationInitializer { CorrelationHandle = handle }); } } } reply = new SendReply() { DisplayName = string.Format(CultureInfo.CurrentUICulture, "SendReplyTo{0}", receive.Properties["DisplayName"].ComputedValue), Request = (Receive)receive.GetCurrentValue(), }; } else { MessageBox.Show( (string)StringResourceDictionary.Instance["receiveActivityCreateReplyErrorLabel"] ?? "Source 'Reply' element not found!", (string)StringResourceDictionary.Instance["MessagingActivityTitle"] ?? "Send", MessageBoxButton.OK, MessageBoxImage.Error); } return(reply); }