/// <summary> /// Adds a collection property descriptor from the given Xml node. /// </summary> /// <param name="propertyNode">The node containing the property descriptor information.</param> private void AddCollectionPropertyDescriptor(XmlNode propertyNode) { Param.AssertNotNull(propertyNode, "propertyNode"); bool aggregate = false; XmlAttribute aggregateNode = propertyNode.Attributes["Aggregate"]; if (aggregateNode != null) { aggregate = bool.Parse(aggregateNode.Value); } // Get the name of the property. string propertyName = ExtractPropertyName(propertyNode); // Create the property descriptor and add it. CollectionPropertyDescriptor propertyDescriptor = new CollectionPropertyDescriptor( propertyName, ExtractFriendlyName(propertyNode), ExtractDescription(propertyNode), ExtractMerge(propertyNode), aggregate); this.propertyDescriptors.Add(propertyName, propertyDescriptor); }
/// <summary> /// Initializes a new instance of the CollectionProperty class. /// </summary> /// <param name="propertyDescriptor">The property descriptor that this value represents.</param> /// <param name="innerCollection">The inner collection.</param> public CollectionProperty(CollectionPropertyDescriptor propertyDescriptor, IEnumerable <string> innerCollection) : base(propertyDescriptor) { Param.RequireNotNull(propertyDescriptor, "propertyDescriptor"); Param.Ignore(innerCollection); if (innerCollection != null) { this.collection = new List <string>(innerCollection); } else { this.collection = new List <string>(); } }
/// <summary> /// Loads and stores a collection property. /// </summary> /// <param name="propertyName">The name of the property to load.</param> /// <param name="propertyNode">The node containing the property.</param> /// <param name="properties">The collection in which to store the property.</param> /// <param name="propertyDescriptors">The collection of property descriptors.</param> private static void LoadCollectionProperty( string propertyName, XmlNode propertyNode, PropertyCollection properties, PropertyDescriptorCollection propertyDescriptors) { Param.AssertValidString(propertyName, "propertyName"); Param.AssertNotNull(propertyNode, "propertyNode"); Param.AssertNotNull(properties, "properties"); Param.AssertNotNull(propertyDescriptors, "propertyDescriptors"); // Create and load the inner property collection. List <string> innerCollection = new List <string>(); // Load the value list. XmlNodeList valueNodes = propertyNode.SelectNodes("Value"); if (valueNodes != null && valueNodes.Count > 0) { foreach (XmlNode valueNode in valueNodes) { if (!string.IsNullOrEmpty(valueNode.InnerText)) { innerCollection.Add(valueNode.InnerText); } } } // If at least one value was loaded, save the proeprty. if (innerCollection.Count > 0) { // Get the property descriptor. CollectionPropertyDescriptor descriptor = propertyDescriptors[propertyName] as CollectionPropertyDescriptor; if (descriptor != null) { // Create the collection node and pass in the inner collection. CollectionProperty collectionProperty = new CollectionProperty(descriptor, innerCollection); // Add this property to the parent collection. properties.Add(collectionProperty); } } }
/// <summary> /// Loads the valid prefixes from the given node.. /// </summary> /// <param name="validPrefixesNode">The node containing the prefixes.</param> /// <param name="settings">The settings collection.</param> private static void LoadValidPrefixes(XmlNode validPrefixesNode, Settings settings) { Param.AssertNotNull(validPrefixesNode, "validPrefixesNode"); Param.AssertNotNull(settings, "settings"); string[] prefixes = validPrefixesNode.InnerText.Split(','); // Get the analyzer. SourceAnalyzer analyzer = settings.Core.GetAnalyzer("StyleCop.CSharp.NamingRules"); if (analyzer != null) { // Get the property descriptor. CollectionPropertyDescriptor propertyDescriptor = analyzer.PropertyDescriptors["Hungarian"] as CollectionPropertyDescriptor; if (propertyDescriptor != null) { settings.SetAddInSettingInternal(analyzer, new CollectionProperty(propertyDescriptor, prefixes)); } } }
/// <summary> /// Initializes a new instance of the CollectionProperty class. /// </summary> /// <param name="propertyDescriptor">The property descriptor that this value represents.</param> public CollectionProperty(CollectionPropertyDescriptor propertyDescriptor) : this(propertyDescriptor, null) { Param.Ignore(propertyDescriptor); }