Пример #1
0
        public void BasicPropertyDictionary()
        {
            PropertyDictionary <ProjectPropertyInstance> properties = new PropertyDictionary <ProjectPropertyInstance>();

            ProjectPropertyInstance p1 = GetPropertyInstance("p1", "v1");
            ProjectPropertyInstance p2 = GetPropertyInstance("p2", "v2");
            ProjectPropertyInstance p3 = GetPropertyInstance("p1", "v1");
            ProjectPropertyInstance p4 = GetPropertyInstance("p2", "v3");

            properties.Set(p1);
            properties.Set(p2);
            properties.Set(p3);
            properties.Set(p1);
            properties.Set(p4);

            Assert.Equal(2, properties.Count);
            Assert.Equal("v1", properties["p1"].EvaluatedValue);
            Assert.Equal("v3", properties["p2"].EvaluatedValue);

            Assert.True(properties.Remove("p1"));
            Assert.Null(properties["p1"]);

            Assert.False(properties.Remove("x"));

            properties.Clear();

            Assert.Empty(properties);
        }
        public void TestRemove_IDictionary_ThrowsException()
        {
            object instance = new object();
            IDictionary <string, object> dictionary = new PropertyDictionary(instance);

            dictionary.Remove("Name");
        }
        public void TestRemove_ICollection_ThrowsException()
        {
            object instance = new object();
            ICollection <KeyValuePair <string, object> > collection = new PropertyDictionary(instance);

            collection.Remove(new KeyValuePair <string, object>("Name", "Whatever"));
        }
Пример #4
0
        /// <summary>
        /// Removes the extended property
        /// </summary>
        /// <param name="key">Property Key</param>
        /// <returns>True if property existed, False if it did not</returns>
        public bool ClearExtendedProperty(string key)
        {
            if (string.IsNullOrEmpty(key))
            {
                throw new ArgumentNullException("key");
            }

            return((_propertyDictionary != null) ? PropertyDictionary.Remove(key) : false);
        }
Пример #5
0
 private static void RemoveFromPropertyDictionary(
     PropertyDictionary <ProjectPropertyInstance> properties,
     IReadOnlyCollection <string> propertyNamesToRemove)
 {
     foreach (var propertyName in propertyNamesToRemove)
     {
         properties.Remove(propertyName);
     }
 }
Пример #6
0
 private static void RemoveFromPropertyDictionary(
     PropertyDictionary <ProjectPropertyInstance> properties,
     string propertyNamesString)
 {
     if (!string.IsNullOrEmpty(propertyNamesString))
     {
         var propertiesToRemove = propertyNamesString.Split(PropertySeparator, StringSplitOptions.RemoveEmptyEntries);
         foreach (string propertyName in propertiesToRemove)
         {
             properties.Remove(propertyName);
         }
     }
 }
Пример #7
0
        public void _AppSettings_SettingChanging(object sender, PropertyChangedEventArgs e)
        {
            if (!_saving)
            {
                try
                {
                    var newSetting = PropertyDictionary <string, object> .Convert(sender);

                    object newVal = newSetting[e.PropertyName];

                    if (newVal != null)
                    {
                        if (!newVal.Equals(OldSettings[e.PropertyName]))
                        {
                            try
                            {
                                if (!_changedSettings.ContainsKey(e.PropertyName))
                                {
                                    AppSettings[e.PropertyName] = newVal;
                                    _changedSettings.Add(e.PropertyName, newVal);
                                }
                            }
                            catch
                            {
                                AppSettings[e.PropertyName] = newVal;
                                _changedSettings.Add(e.PropertyName, newVal);
                            }
                        }
                        else
                        {
                            try
                            {
                                _changedSettings.Remove(e.PropertyName);
                            }
                            catch
                            { }
                        }

                        if (!_applyAlwaysEnabled)
                        {
                            ApplyBtn.Enabled = _changedSettings.Count > 0;
                        }
                    }
                }
                catch
                { }
            }
        }
Пример #8
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());
        }
        public void EqualsEndEnd()
        {
            MSBuildNameIgnoreCaseComparer comparer = MSBuildNameIgnoreCaseComparer.Mutable;
            PropertyDictionary <ProjectPropertyInstance> dictionary = new PropertyDictionary <ProjectPropertyInstance>(comparer);

            ProjectPropertyInstance p1 = ProjectPropertyInstance.Create("aabaaaa", "value1");
            ProjectPropertyInstance p2 = ProjectPropertyInstance.Create("baaaa", "value2");

            dictionary.Set(p1);
            dictionary.Set(p2);

            string constraint = "aabaaa";

            ProjectPropertyInstance p3 = ProjectPropertyInstance.Create("abaaa", "value3");

            dictionary.Set(p3);

            // Should match o3
            ProjectPropertyInstance value1 = comparer.GetValueWithConstraints <ProjectPropertyInstance>(dictionary, constraint, 1, 5);

            Assert.True(Object.ReferenceEquals(p3, value1)); // "Should have returned the 'abaaa' value"

            dictionary.Remove("abaaa");                      // get rid of o3

            ProjectPropertyInstance value2 = comparer.GetValueWithConstraints <ProjectPropertyInstance>(dictionary, constraint, 1, 5);

            Assert.Null(value2); // "Should not have been a match in the dictionary"

            // Even if the string is exactly the same, if only a substring is being compared, then although it
            // will be judged equal, the hash codes will NOT be the same, and for that reason, a lookup in the
            // dictionary will fail.
            int originalHashCode = comparer.GetHashCode("aabaaa");

            try
            {
                comparer.SetConstraintsForUnitTestingOnly(constraint, 1, 5);

                Assert.True(comparer.Equals("aabaaa", constraint)); // same on both sides
                Assert.NotEqual(originalHashCode, comparer.GetHashCode(constraint));
            }
            finally
            {
                comparer.RemoveConstraintsForUnitTestingOnly();
            }
        }
Пример #10
0
        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);
                }
            }
        }
        public void EqualsEndEnd()
        {
            PropertyDictionary<ProjectPropertyInstance> dictionary = new PropertyDictionary<ProjectPropertyInstance>();

            ProjectPropertyInstance p1 = ProjectPropertyInstance.Create("aabaaaa", "value1");
            ProjectPropertyInstance p2 = ProjectPropertyInstance.Create("baaaa", "value2");
            dictionary.Set(p1);
            dictionary.Set(p2);

            string constraint = "aabaaa";

            ProjectPropertyInstance p3 = ProjectPropertyInstance.Create("abaaa", "value3");
            dictionary.Set(p3);

            // Should match o3
            ProjectPropertyInstance value1 = MSBuildNameIgnoreCaseComparer.Mutable.GetValueWithConstraints<ProjectPropertyInstance>(dictionary, constraint, 1, 5);

            Assert.IsTrue(Object.ReferenceEquals(p3, value1), "Should have returned the 'abaaa' value");

            dictionary.Remove("abaaa"); // get rid of o3

            ProjectPropertyInstance value2 = MSBuildNameIgnoreCaseComparer.Mutable.GetValueWithConstraints<ProjectPropertyInstance>(dictionary, constraint, 1, 5);

            Assert.IsNull(value2, "Should not have been a match in the dictionary");

            // Even if the string is exactly the same, if only a substring is being compared, then although it 
            // will be judged equal, the hash codes will NOT be the same, and for that reason, a lookup in the 
            // dictionary will fail.  
            int originalHashCode = MSBuildNameIgnoreCaseComparer.Mutable.GetHashCode("aabaaa");
            try
            {
                MSBuildNameIgnoreCaseComparer.Mutable.SetConstraintsForUnitTestingOnly(constraint, 1, 5);

                Assert.IsTrue(MSBuildNameIgnoreCaseComparer.Mutable.Equals("aabaaa", constraint)); // same on both sides
                Assert.AreNotEqual(originalHashCode, MSBuildNameIgnoreCaseComparer.Mutable.GetHashCode(constraint));
            }
            finally
            {
                MSBuildNameIgnoreCaseComparer.Mutable.RemoveConstraintsForUnitTestingOnly();
            }
        }