/// <summary> /// Gets all the attributes assigned in the xml file for this parameter or all of the nested switches for /// this parameter group /// </summary> private static Property ObtainAttributes(XamlTypes.BaseProperty baseProperty, Property parameterGroup) { Property parameter; if (parameterGroup != null) { parameter = parameterGroup.Clone(); } else { parameter = new Property(); } XamlTypes.BoolProperty boolProperty = baseProperty as XamlTypes.BoolProperty; XamlTypes.DynamicEnumProperty dynamicEnumProperty = baseProperty as XamlTypes.DynamicEnumProperty; XamlTypes.EnumProperty enumProperty = baseProperty as XamlTypes.EnumProperty; XamlTypes.IntProperty intProperty = baseProperty as XamlTypes.IntProperty; XamlTypes.StringProperty stringProperty = baseProperty as XamlTypes.StringProperty; XamlTypes.StringListProperty stringListProperty = baseProperty as XamlTypes.StringListProperty; parameter.IncludeInCommandLine = baseProperty.IncludeInCommandLine; if (baseProperty.Name != null) { parameter.Name = baseProperty.Name; } if (boolProperty != null && !String.IsNullOrEmpty(boolProperty.ReverseSwitch)) { parameter.Reversible = "true"; } // Determine the type for this property. if (boolProperty != null) { parameter.Type = PropertyType.Boolean; } else if (enumProperty != null) { parameter.Type = PropertyType.String; } else if (dynamicEnumProperty != null) { parameter.Type = PropertyType.String; } else if (intProperty != null) { parameter.Type = PropertyType.Integer; } else if (stringProperty != null) { parameter.Type = PropertyType.String; } else if (stringListProperty != null) { parameter.Type = PropertyType.StringArray; } // We might need to override this type based on the data source, if it specifies a source type of 'Item'. if (baseProperty.DataSource != null) { if (!String.IsNullOrEmpty(baseProperty.DataSource.SourceType)) { if (baseProperty.DataSource.SourceType.Equals("Item", StringComparison.OrdinalIgnoreCase)) { parameter.Type = PropertyType.ItemArray; } } } if (intProperty != null) { parameter.Max = intProperty.MaxValue != null?intProperty.MaxValue.ToString() : null; parameter.Min = intProperty.MinValue != null?intProperty.MinValue.ToString() : null; } if (boolProperty != null) { parameter.ReverseSwitchName = boolProperty.ReverseSwitch; } if (baseProperty.Switch != null) { parameter.SwitchName = baseProperty.Switch; } if (stringListProperty != null) { parameter.Separator = stringListProperty.Separator; } if (baseProperty.Default != null) { parameter.DefaultValue = baseProperty.Default; } parameter.Required = baseProperty.IsRequired.ToString().ToLower(CultureInfo.InvariantCulture); if (baseProperty.Category != null) { parameter.Category = baseProperty.Category; } if (baseProperty.DisplayName != null) { parameter.DisplayName = baseProperty.DisplayName; } if (baseProperty.Description != null) { parameter.Description = baseProperty.Description; } if (baseProperty.SwitchPrefix != null) { parameter.Prefix = baseProperty.SwitchPrefix; } return(parameter); }
/// <summary> /// Fills in the property data structure /// </summary> private bool ParseParameter(XamlTypes.BaseProperty baseProperty, LinkedList <Property> propertyList, Property property, Dictionary <string, Property> argumentDependencyLookup) { Property propertyToAdd = ObtainAttributes(baseProperty, property); if (String.IsNullOrEmpty(propertyToAdd.Name)) { propertyToAdd.Name = "AlwaysAppend"; } // generate the list of parameters in order if (!_switchOrderList.Contains(propertyToAdd.Name)) { _switchOrderList.Add(propertyToAdd.Name); } else { throw new XamlParseException(ResourceUtilities.FormatResourceStringIgnoreCodeAndKeyword("Xaml.DuplicatePropertyName", propertyToAdd.Name)); } // Inherit the Prefix from the Tool if (String.IsNullOrEmpty(propertyToAdd.Prefix)) { propertyToAdd.Prefix = DefaultPrefix; } // If the property is an enum type, parse that. XamlTypes.EnumProperty enumProperty = baseProperty as XamlTypes.EnumProperty; if (enumProperty != null) { foreach (XamlTypes.EnumValue enumValue in enumProperty.AdmissibleValues) { var value = new Value { Name = enumValue.Name, SwitchName = enumValue.Switch }; if (value.SwitchName == null) { value.SwitchName = String.Empty; } value.DisplayName = enumValue.DisplayName; value.Description = enumValue.Description; value.Prefix = enumValue.SwitchPrefix; if (String.IsNullOrEmpty(value.Prefix)) { value.Prefix = enumProperty.SwitchPrefix; } if (String.IsNullOrEmpty(value.Prefix)) { value.Prefix = DefaultPrefix; } if (enumValue.Arguments.Count > 0) { value.Arguments = new List <Argument>(); foreach (XamlTypes.Argument argument in enumValue.Arguments) { var arg = new Argument { Parameter = argument.Property, Separator = argument.Separator, Required = argument.IsRequired }; value.Arguments.Add(arg); } } if (value.Prefix == null) { value.Prefix = propertyToAdd.Prefix; } propertyToAdd.Values.Add(value); } } // build the dependencies and the values for a parameter foreach (XamlTypes.Argument argument in baseProperty.Arguments) { // To refactor into a separate func if (propertyToAdd.Arguments == null) { propertyToAdd.Arguments = new List <Argument>(); } var arg = new Argument { Parameter = argument.Property, Separator = argument.Separator, Required = argument.IsRequired }; propertyToAdd.Arguments.Add(arg); } if (argumentDependencyLookup != null && !argumentDependencyLookup.ContainsKey(propertyToAdd.Name)) { argumentDependencyLookup.Add(propertyToAdd.Name, propertyToAdd); } // We've read any enumerated values and any dependencies, so we just // have to add the property propertyList.AddLast(propertyToAdd); return(true); }