Add() 공개 메소드

Adds a property to the collection.
public Add ( string name, string value ) : void
name string The name of the property.
value string The value to assign to the property.
리턴 void
        public void Adds_value_to_existing_key_value()
        {
            PropertyDictionary properties = new PropertyDictionary(null);
            properties.Add(Key, ExistingValue.ToString());

            PropertyDictionaryHelper.AddOrUpdateInt(properties, Key, Value);

            Assert.AreEqual(int.Parse(properties[Key], CultureInfo.InvariantCulture), Value + ExistingValue);
        }
        public void Replaces_key_if_key_does_exists()
        {
            PropertyDictionary properties = new PropertyDictionary(null);
            properties.Add(Key, ExistingValue.ToString());

            PropertyDictionaryHelper.SetInt(properties, Key, Value);

            Assert.IsNotNull(properties[Key]);
        }
        public void Replaces_value_by_key_if_key_does_exists()
        {
            PropertyDictionary properties = new PropertyDictionary(null);
            properties.Add(Key, ExistingValue.ToString());

            PropertyDictionaryHelper.SetInt(properties, Key, Value);

            Assert.AreEqual(int.Parse(properties[Key], CultureInfo.InvariantCulture), 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);
			}
		}
예제 #5
0
        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());
        }