- Retreive Arguments of a Workflow (with default values)?
- // Just an holder for InArgument informations
- class InArgumentInfo
- {
- public string InArgumentName { get; set; }
- public string InArgumentDescription { get; set; }
- public bool InArgumentIsRequired { get; set; }
- }
- static ICollection<InArgumentInfo> GetInArgumentsInfos(Activity activity)
- {
- var properties = activity.GetType()
- .GetProperties()
- .Where(p => typeof(InArgument).IsAssignableFrom(p.PropertyType))
- .ToList();
- var argumentsCollection = new Collection<InArgumentInfo>();
- foreach (var property in properties)
- {
- var descAttribute = property
- .GetCustomAttributes(false)
- .OfType<DescriptionAttribute>()
- .FirstOrDefault();
- string description = descAttribute != null && !string.IsNullOrEmpty(descAttribute.Description) ?
- descAttribute.Description :
- string.Empty;
- bool isRequired = property
- .GetCustomAttributes(false)
- .OfType<RequiredArgumentAttribute>()
- .Any();
- argumentsCollection.Add(new InArgumentInfo
- {
- InArgumentName = property.Name,
- InArgumentDescription = description,
- InArgumentIsRequired = isRequired
- });
- }
- return argumentsCollection;
- }
- var dynamicActivity = ActivityXamlServices.Load(foo) as DynamicActivity
- foreach(DynamicActivityProperty prop in dynamicActivity.Properties)
- {
- // ...
- }
- foreach (var prop in dynamicActivity .Properties)
- {
- object defaultValue;
- if (prop.Value == null)
- {
- defaultValue = null;
- }
- else
- {
- Type genericTypeDefinition = prop.Type.GetGenericTypeDefinition();
- if (genericTypeDefinition == typeof(InArgument<>) || genericTypeDefinition == typeof(InOutArgument<>))
- {
- var valueProp = prop.Value.GetType().GetProperty("Expression", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.DeclaredOnly);
- var expression = valueProp.GetValue(prop.Value, null);
- var expressionValueProp = expression.GetType().GetProperty("Value");
- defaultValue = expressionValueProp.GetValue(expression, null);
- }
- }
- }