public void TestContains_Explicit_ValueDoesNotMatch_ReturnsFalse() { var person = new { Name = "Bob" }; ICollection <KeyValuePair <string, object> > collection = new PropertyDictionary(person); bool contains = collection.Contains(new KeyValuePair <string, object>("Name", "Sally")); Assert.IsFalse(contains, "The pair should not have been found."); }
public void TestContains_Explicit_PairExists_ReturnsTrue() { var person = new { Name = "Bob" }; ICollection <KeyValuePair <string, object> > collection = new PropertyDictionary(person); bool contains = collection.Contains(new KeyValuePair <string, object>("Name", "Bob")); Assert.IsTrue(contains, "Did not find the pair."); }
public void SetVariable(string name, string value) { PropertyDictionary properties = Project.Properties; if (properties.Contains(name)) { properties[name] = value; } else { properties.Add(name, value); } }
public static void SetInt(PropertyDictionary instance, string key, int value) { Ensure.ArgumentIsNotNull(instance, "instance"); Ensure.ArgumentIsNotNullOrEmptyString(key, "key"); string valueToSet = value.ToString(CultureInfo.InvariantCulture); if (instance.Contains(key)) { instance[key] = valueToSet; } else { instance.Add(key, valueToSet); } }
private static void SetUpProperties(ArrayList attributeList, Task task, XmlNode xml, PropertyDictionary oldPropertyValues) { PropertyDictionary projectProperties = task.Project.Properties; StringBuilder logMessage = new StringBuilder(); foreach (MacroAttribute macroAttribute in attributeList) { string attributeName = macroAttribute.name; XmlAttribute xmlAttribute = xml.Attributes[attributeName]; string value = null; if (xmlAttribute != null) { value = projectProperties.ExpandProperties(xmlAttribute.Value, null); } else if (macroAttribute.defaultValue != null) { value = macroAttribute.defaultValue; } string localPropertyName = macroAttribute.LocalPropertyName; task.Log(Level.Debug, "Setting property " + localPropertyName + " to " + value); if (logMessage.Length > 0) { logMessage.Append(", "); } logMessage.Append(localPropertyName); logMessage.Append(" = '"); logMessage.Append(value); logMessage.Append("'"); if (projectProperties.Contains(localPropertyName)) { oldPropertyValues.Add(localPropertyName, projectProperties[localPropertyName]); projectProperties.Remove(localPropertyName); } if (value != null) { projectProperties.Add(localPropertyName, value); } } task.Log(Level.Info, logMessage.ToString()); }
private static void RestoreProperties(ArrayList attributeList, Task task, PropertyDictionary oldValues) { PropertyDictionary projectProperties = task.Project.Properties; foreach (MacroAttribute macroAttribute in attributeList) { string localPropertyName = macroAttribute.LocalPropertyName; string oldValue = oldValues[localPropertyName]; if (projectProperties.Contains(localPropertyName)) { projectProperties.Remove(localPropertyName); } if (oldValue != null) { projectProperties.Add(localPropertyName, oldValue); } } }