コード例 #1
0
        private static void UpdateTypeArgument(ModelItem modelItem, Type value)
        {
            if (value != null)
            {
                Type oldModelItemType = modelItem.ItemType;

                Type newModelItemType = oldModelItemType.GetGenericTypeDefinition().MakeGenericType(value);

                ModelItem newModelItem = ModelFactory.CreateItem(modelItem.GetEditingContext(), Activator.CreateInstance(newModelItemType));
                MorphHelper.MorphObject(modelItem, newModelItem);
                MorphHelper.MorphProperties(modelItem, newModelItem);

                if (oldModelItemType.IsSubclassOf(typeof(Activity)) && newModelItemType.IsSubclassOf(typeof(Activity)))
                {
                    if (string.Equals((string)modelItem.Properties["DisplayName"].ComputedValue, GetActivityDefaultName(oldModelItemType), StringComparison.Ordinal))
                    {
                        newModelItem.Properties["DisplayName"].SetValue(GetActivityDefaultName(newModelItemType));
                    }
                }

                DesignerView designerView = modelItem.GetEditingContext().Services.GetService <DesignerView>();
                if (designerView != null)
                {
                    Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Render, (Action)(() =>
                    {
                        if (designerView.RootDesigner != null && ((WorkflowViewElement)designerView.RootDesigner).ModelItem == modelItem)
                        {
                            designerView.MakeRootDesigner(newModelItem);
                        }
                        Selection.SelectOnly(modelItem.GetEditingContext(), newModelItem);
                    }));
                }
            }
        }
コード例 #2
0
        private static void UpdateTypeArgument(ModelItem modelItem, Int32 argumentIndex, Type newGenericType)
        {
            Type itemType = modelItem.ItemType;

            Type[] genericTypes = itemType.GetGenericArguments();

            // Replace the type being changed
            genericTypes[argumentIndex] = newGenericType;

            Type           newType           = itemType.GetGenericTypeDefinition().MakeGenericType(genericTypes);
            EditingContext editingContext    = modelItem.GetEditingContext();
            Object         instanceOfNewType = Activator.CreateInstance(newType);
            ModelItem      newModelItem      = ModelFactory.CreateItem(editingContext, instanceOfNewType);

            using (ModelEditingScope editingScope = newModelItem.BeginEdit("Change type argument"))
            {
                MorphHelper.MorphObject(modelItem, newModelItem);
                MorphHelper.MorphProperties(modelItem, newModelItem);

                if (itemType.IsSubclassOf(typeof(Activity)) && newType.IsSubclassOf(typeof(Activity)))
                {
                    if (DisplayNameRequiresUpdate(modelItem))
                    {
                        // Update to the new display name
                        String newDisplayName = GetActivityDefaultName(newType);

                        newModelItem.Properties[DisplayName].SetValue(newDisplayName);
                    }
                }

                DesignerUpdater.UpdateModelItem(modelItem, newModelItem);

                editingScope.Complete();
            }
        }
コード例 #3
0
        private static void UpdateTypeArgument(ModelItem modelItem, Type argType, int argIndex)
        {
            if (modelItem == null)
            {
                return;
            }

            var argTypes = modelItem.ItemType.GetGenericArguments();

            argTypes[argIndex] = argType;

            var editingContext = modelItem.GetEditingContext();
            var itemType       = modelItem.ItemType;
            var type           = itemType.GetGenericTypeDefinition().MakeGenericType(argTypes);
            var newModelItem   = ModelFactory.CreateItem(editingContext, Activator.CreateInstance(type));

            MorphHelper.MorphObject(modelItem, newModelItem);
            MorphHelper.MorphProperties(modelItem, newModelItem);

            if (itemType.IsSubclassOf(typeof(Activity)) &&
                type.IsSubclassOf(typeof(Activity)) &&
                string.Equals((string)modelItem.Properties[DisplayName].ComputedValue, GetActivityDefaultName(itemType), StringComparison.Ordinal))
            {
                newModelItem.Properties[DisplayName].SetValue(GetActivityDefaultName(type));
            }

            var service = editingContext.Services.GetService <DesignerView>();

            if (service == null)
            {
                return;
            }

            Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Render, new Action(() =>
            {
                if (service.RootDesigner != null && ((WorkflowViewElement)service.RootDesigner).ModelItem == modelItem)
                {
                    service.MakeRootDesigner(newModelItem);
                }

                Selection.SelectOnly(editingContext, newModelItem);
            }));
        }