1 //----------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation. All rights reserved.
3 //----------------------------------------------------------------
5 namespace System.Activities.Presentation.Xaml
7 using System.Activities.Presentation.Model;
8 using System.Collections.Generic;
10 internal static class ActivityBuilderHelper
12 internal static bool IsActivityBuilderType(ModelItem modelItem)
14 if (null == modelItem)
16 throw FxTrace.Exception.AsError(new ArgumentNullException("modelItem"));
18 return modelItem.ItemType.IsAssignableFrom(typeof(ActivityBuilder));
21 internal static List<Variable> GetVariables(object input)
25 throw FxTrace.Exception.AsError(new ArgumentNullException("input"));
27 ModelItem astAsModelItem = input as ModelItem;
28 ActivityBuilder instance = input as ActivityBuilder;
29 if (null != astAsModelItem)
31 if (!astAsModelItem.ItemType.IsAssignableFrom(typeof(ActivityBuilder)))
33 throw FxTrace.Exception.AsError(new InvalidCastException(astAsModelItem.ItemType.FullName));
35 instance = (ActivityBuilder)astAsModelItem.GetCurrentValue();
37 else if (null == instance)
39 throw FxTrace.Exception.AsError(new InvalidCastException(input.GetType().FullName));
42 List<Variable> variables = new List<Variable>();
43 foreach (DynamicActivityProperty property in instance.Properties)
47 Variable autoVariable = GetVariableFromProperty(property);
48 if (autoVariable != null)
50 variables.Add(autoVariable);
57 internal static Variable GetVariableFromProperty(DynamicActivityProperty property)
59 Type variableType = null;
60 Variable autoVariable = null;
62 if (property.Type != null)
64 Type propertyType = property.Type;
66 // if the property is an Argument<T> create a variable of type T
67 if (propertyType != null && typeof(Argument).IsAssignableFrom(propertyType))
69 if (propertyType.IsGenericType)
71 variableType = propertyType.GetGenericArguments()[0];
75 variableType = typeof(object);
79 if (variableType != null)
81 autoVariable = Variable.Create(property.Name, variableType, VariableModifiers.None);
82 Argument argument = property.Value as Argument;
85 autoVariable.Default = argument.Expression;