本文整理汇总了C#中PropertyCollection.Add方法的典型用法代码示例。如果您正苦于以下问题:C# PropertyCollection.Add方法的具体用法?C# PropertyCollection.Add怎么用?C# PropertyCollection.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PropertyCollection
的用法示例。
在下文中一共展示了PropertyCollection.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadDetail
protected virtual void ReadDetail(XPathNavigator navigator, PropertyCollection collection, ReadingJournal journal)
{
Dictionary<string, string> attributes = GetAttributes(navigator);
Type type = attributes["typeName"].ToType();
if (type != typeof(ContentItem))
{
collection.Add(Parse(navigator.Value, type));
}
else
{
int referencedItemID = int.Parse(navigator.Value);
ContentItem referencedItem = journal.Find(referencedItemID);
if (referencedItem != null)
collection.Add(referencedItem);
else
journal.ItemAdded += (sender, e) =>
{
if (e.AffectedItem.ID == referencedItemID)
{
collection.Add(e.AffectedItem);
}
};
}
}
示例2: AddDuplicateNameTest
public void AddDuplicateNameTest()
{
PropertyCollection collection = new PropertyCollection(new string[0]);
Property prop1 = new StringProperty("Name", "Treefrog");
Property prop2 = new StringProperty("Name", "Amphibian");
collection.Add(prop1);
collection.Add(prop2);
}
示例3: SetUp
public void SetUp()
{
_injector = new Injector();
_properties = new PropertyCollection();
_properties.Add(new Property("scriptkey1", "scriptvalue1"));
_properties.Add(new Property("foo", "scriptbar"));
_properties.Add(new Property("thing", "key1"));
_properties.Add(new Property("foo", "globalbar"));
_properties.Add(new Property("globalkey1", "globalvalue1"));
}
示例4: AddBooleanProperty
private static void AddBooleanProperty(string propertyName, bool value, PropertyCollection properties, PropertyDescriptorCollection propertyDescriptors)
{
PropertyDescriptor<bool> propertyDescriptor = propertyDescriptors[propertyName] as PropertyDescriptor<bool>;
if (propertyDescriptor != null)
{
properties.Add(new BooleanProperty(propertyDescriptor, value));
}
}
示例5: LoadBooleanProperty
private static void LoadBooleanProperty(string propertyName, XmlNode propertyNode, PropertyCollection properties, PropertyDescriptorCollection propertyDescriptors)
{
bool flag;
if (bool.TryParse(propertyNode.InnerText, out flag))
{
PropertyDescriptor<bool> propertyDescriptor = propertyDescriptors[propertyName] as PropertyDescriptor<bool>;
if (propertyDescriptor != null)
{
properties.Add(new BooleanProperty(propertyDescriptor, flag));
}
}
}
示例6: AddPropertyTest
public void AddPropertyTest()
{
PropertyCollection collection = new PropertyCollection(new string[0]);
AttachEvents(collection);
Property prop = new StringProperty("test", "orange");
collection.PropertyAdded += (s, e) =>
{
Assert.AreSame(prop, e.Property);
Assert.AreEqual(1, collection.Count);
Assert.IsTrue(collection.Contains("test"));
Assert.IsTrue(collection.Contains(prop));
};
collection.Add(prop);
Assert.AreEqual(EventFlags.PropertyAdded | EventFlags.Modified, _eventsFired);
}
示例7: LoadIntProperty
private static void LoadIntProperty(string propertyName, XmlNode propertyNode, PropertyCollection properties, PropertyDescriptorCollection propertyDescriptors)
{
int num;
if (int.TryParse(propertyNode.InnerText, NumberStyles.Any, CultureInfo.InvariantCulture, out num))
{
PropertyDescriptor<int> propertyDescriptor = propertyDescriptors[propertyName] as PropertyDescriptor<int>;
properties.Add(new IntProperty(propertyDescriptor, num));
}
}
示例8: LoadCollectionProperty
private static void LoadCollectionProperty(string propertyName, XmlNode propertyNode, PropertyCollection properties, PropertyDescriptorCollection propertyDescriptors)
{
List<string> innerCollection = new List<string>();
XmlNodeList list2 = propertyNode.SelectNodes("Value");
if ((list2 != null) && (list2.Count > 0))
{
foreach (XmlNode node in list2)
{
if (!string.IsNullOrEmpty(node.InnerText))
{
innerCollection.Add(node.InnerText);
}
}
}
if (innerCollection.Count > 0)
{
CollectionPropertyDescriptor propertyDescriptor = propertyDescriptors[propertyName] as CollectionPropertyDescriptor;
CollectionProperty property = new CollectionProperty(propertyDescriptor, innerCollection);
properties.Add(property);
}
}
示例9: AddNullPropertyTest
public void AddNullPropertyTest()
{
PropertyCollection collection = new PropertyCollection(new string[0]);
collection.Add(null);
}
示例10: LoadIntProperty
/// <summary>
/// Loads and stores an integer 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 LoadIntProperty(string propertyName, XmlNode propertyNode, PropertyCollection properties, PropertyDescriptorCollection propertyDescriptors)
{
Param.AssertValidString(propertyName, "propertyName");
Param.AssertNotNull(propertyNode, "propertyNode");
Param.AssertNotNull(properties, "properties");
Param.AssertNotNull(propertyDescriptors, "propertyDescriptors");
// Skip corrupted properties.
int value;
if (int.TryParse(propertyNode.InnerText, NumberStyles.Any, CultureInfo.InvariantCulture, out value))
{
// Get the property descriptor.
PropertyDescriptor<int> descriptor = propertyDescriptors[propertyName] as PropertyDescriptor<int>;
// Create and add the property.
properties.Add(new IntProperty(descriptor, value));
}
}
示例11: AddBooleanProperty
/// <summary>
/// Adds a boolean property.
/// </summary>
/// <param name="propertyName">
/// The name of the property.
/// </param>
/// <param name="value">
/// The property value.
/// </param>
/// <param name="properties">
/// The collection of properties.
/// </param>
/// <param name="propertyDescriptors">
/// The collection of property descriptors.
/// </param>
private static void AddBooleanProperty(string propertyName, bool value, PropertyCollection properties, PropertyDescriptorCollection propertyDescriptors)
{
Param.AssertValidString(propertyName, "propertyName");
Param.Ignore(value);
Param.AssertNotNull(properties, "properties");
Param.AssertNotNull(propertyDescriptors, "propertyDescriptors");
// Get the property descriptor.
PropertyDescriptor<bool> descriptor = propertyDescriptors[propertyName] as PropertyDescriptor<bool>;
if (descriptor != null)
{
// Create and add the property.
properties.Add(new BooleanProperty(descriptor, value));
}
}
示例12: MergeCollectionProperties
private static void MergeCollectionProperties(PropertyCollection mergedPropertyCollection, PropertyValue originalProperty, PropertyValue overridingProperty)
{
CollectionProperty property = (CollectionProperty) originalProperty;
CollectionProperty property2 = (CollectionProperty) overridingProperty;
CollectionProperty property3 = new CollectionProperty((CollectionPropertyDescriptor) property.PropertyDescriptor);
mergedPropertyCollection.Add(property3);
foreach (string str in property2.Values)
{
property3.Add(str);
}
if (property.Aggregate)
{
foreach (string str2 in property.Values)
{
if (!property3.Contains(str2))
{
property3.Add(str2);
}
}
}
}
示例13: MergePropertyCollections
/// <summary>
/// Merged two sets of property collections together.
/// </summary>
/// <param name="originalPropertyCollection">
/// The original property collection.
/// </param>
/// <param name="overridingPropertyCollection">
/// The overriding property collection.
/// </param>
/// <param name="mergedPropertyCollection">
/// The merged property collection.
/// </param>
internal static void MergePropertyCollections(
PropertyCollection originalPropertyCollection, PropertyCollection overridingPropertyCollection, PropertyCollection mergedPropertyCollection)
{
Param.Ignore(originalPropertyCollection);
Param.Ignore(overridingPropertyCollection);
Param.AssertNotNull(mergedPropertyCollection, "mergedPropertyCollection");
// The merge is based on whether one or both files are present.
if (originalPropertyCollection == null && overridingPropertyCollection != null)
{
// There are no settings in the original settings file, only settings from the overriding file.
foreach (PropertyValue property in overridingPropertyCollection)
{
mergedPropertyCollection.Add(property.Clone());
}
}
else if (originalPropertyCollection != null && overridingPropertyCollection == null)
{
// There are no settings from the overriding settings file, only settings from the original file.
foreach (PropertyValue property in originalPropertyCollection)
{
// Only take a property from the original collection if the property is supposed to be merged.
if (property.PropertyDescriptor.Merge)
{
mergedPropertyCollection.Add(property.Clone());
}
}
}
else if (originalPropertyCollection != null && overridingPropertyCollection != null)
{
// There are settings in both settings files. Fist, loop through each property collection
// in the original settings file.
foreach (PropertyValue originalProperty in originalPropertyCollection)
{
if (originalProperty.PropertyDescriptor.Merge)
{
// Try to find a corresponding property in the overriding settings file.
PropertyValue overridingProperty = overridingPropertyCollection[originalProperty.PropertyName];
if (overridingProperty == null)
{
// There is no corresponding overriding property. Just add the original property.
mergedPropertyCollection.Add(originalProperty.Clone());
}
else
{
// Merge the two property value collections together depending on the property type.
switch (originalProperty.PropertyType)
{
case PropertyType.Int:
case PropertyType.String:
case PropertyType.Boolean:
mergedPropertyCollection.Add(overridingProperty.Clone());
break;
case PropertyType.Collection:
MergeCollectionProperties(mergedPropertyCollection, originalProperty, overridingProperty);
break;
default:
Debug.Fail("Unexpected property type.");
break;
}
}
}
}
// Now look through each property in the overriding property collection. If there is any
// property here which is not contained in the merged collection, just add it directly.
// This means that it was not present in the original collection.
foreach (PropertyValue overridingProperty in overridingPropertyCollection)
{
PropertyValue mergedProperty = mergedPropertyCollection[overridingProperty.PropertyName];
if (mergedProperty == null)
{
mergedPropertyCollection.Add(overridingProperty.Clone());
}
}
}
mergedPropertyCollection.IsReadOnly = true;
}
示例14: RenamePropertyTest
public void RenamePropertyTest()
{
PropertyCollection collection = new PropertyCollection(new string[0]);
AttachEvents(collection);
StringProperty prop = new StringProperty("test", "orange");
collection.PropertyRenamed += (s, e) =>
{
Assert.AreEqual("test", e.OldName);
Assert.AreEqual("two", e.NewName);
Assert.AreEqual(1, collection.Count);
Assert.IsFalse(collection.Contains("test"));
Assert.IsTrue(collection.Contains("two"));
Assert.IsTrue(collection.Contains(prop));
};
collection.Add(prop);
_eventsFired = EventFlags.None;
prop.Name = "two";
Assert.AreEqual(EventFlags.PropertyRenamed | EventFlags.Modified, _eventsFired);
}
示例15: readProperties
private void readProperties(PropertyCollection properties, Type ownerType)
{
foreach (string subElement in _reader.ReadSubElements())
{
PropertyArt propertyArt = getPropertyArtFromString(subElement);
if (propertyArt != PropertyArt.Unknown)
{
// check if the property with the name exists
string subPropertyName = _reader.GetAttributeAsString(Attributes.Name);
if (string.IsNullOrEmpty(subPropertyName)) continue;
// estimating the propertyInfo
PropertyInfo subPropertyInfo = ownerType.GetProperty(subPropertyName);
if (subPropertyInfo != null)
{
Property subProperty = deserialize(propertyArt, subPropertyInfo.PropertyType);
properties.Add(subProperty);
}
}
}
}