/// <summary> /// Shoud ignore this property? /// </summary> /// <param name="propertyName">property name</param> /// <param name="owner">owner</param> /// <param name="whatToIgnore">Valueonly or Value and name to ignore?</param> /// <returns></returns> private static bool ShouldIgnoreProperty(string propertyName, object owner, IgnoreProperty whatToIgnore) { PropertyToIgnore property = null; foreach (string key in _skipProperties.Keys) { if (String.Equals(key, propertyName, StringComparison.InvariantCulture) || key.StartsWith(propertyName + "___owner___")) { property = _skipProperties[key]; if (whatToIgnore == property.WhatToIgnore && ((null == property.Owner) || _DoesTypeMatch(owner.GetType(), property.Owner))) { return(true); } } } return(false); }
/// <summary> /// Uses same PropertyToIgnore type as TreeComparer. /// </summary> /// <param name="propertyName"></param> /// <param name="type"></param> /// <param name="skipProps"></param> /// <returns></returns> public static bool ShouldIgnoreProperty(string propertyName, Type type, Dictionary <string, PropertyToIgnore> skipProps) { PropertyToIgnore property = null; foreach (string key in skipProps.Keys) { if (String.Equals(key, propertyName, StringComparison.InvariantCulture) || key.StartsWith(propertyName + "___owner___")) { property = skipProps[key]; if ((null == property.Owner) || DoesTypeMatch(type, property.Owner)) { return(true); } } } return(false); }
/// <summary> /// Read properties to skip from PropertiesToSkip.xml. If this file /// exists under the current working directory, use the one there. /// Otherwise, use the file built in the ClientTestLibrary Assembly. /// </summary> /// <param name="fileName">Name of config file for specifying properties.</param> /// <returns>Hashtable containing properties should be skiped</returns> public static Dictionary <string, PropertyToIgnore> ReadSkipProperties(string fileName) { Dictionary <string, PropertyToIgnore> PropertiesToSkip = new Dictionary <string, PropertyToIgnore>(); // // Load PropertiesToSkip.xml document from assembly resources. // XmlDocument doc = new XmlDocument(); Stream xmlFileStream = null; if (File.Exists(fileName)) { SendCompareMessage("Opening '" + fileName + "' from the current directory."); xmlFileStream = File.OpenRead(fileName); } else { SendCompareMessage("Opening '" + fileName + "' from the Assembly."); Assembly asm = Assembly.GetAssembly(typeof(TreeComparer)); xmlFileStream = asm.GetManifestResourceStream(fileName); if (xmlFileStream == null) { throw new ArgumentException("The file '" + fileName + "' cannot be loaded.", "fileName"); } } try { StreamReader reader = new StreamReader(xmlFileStream); doc.LoadXml(reader.ReadToEnd()); } finally { xmlFileStream.Close(); } // // Store properties to skip in collection. // XmlNodeList properties = doc.GetElementsByTagName("PropertyToSkip"); foreach (XmlNode property in properties) { string propertyName = GetAttributeValue(property, "PropertyName"); string ignore = GetAttributeValue(property, "Ignore"); string owner = GetAttributeValue(property, "Owner"); IgnoreProperty whatToIgnore; if (null == ignore || 0 == String.Compare(ignore, "ValueOnly")) { whatToIgnore = IgnoreProperty.IgnoreValueOnly; } else if (0 == String.Compare(ignore, "NameAndValue")) { whatToIgnore = IgnoreProperty.IgnoreNameAndValue; } else { throw new Exception("'Ignore' attribute value not recognized: " + ignore); } PropertyToIgnore newItem = new PropertyToIgnore(); newItem.WhatToIgnore = whatToIgnore; if (!String.IsNullOrEmpty(owner)) { newItem.Owner = owner; } try { if (PropertiesToSkip.ContainsKey(propertyName)) { SendCompareMessage(propertyName); } PropertiesToSkip.Add(propertyName + "___owner___" + owner, newItem); } catch (Exception ex) { SendCompareMessage(ex.Message); } } return(PropertiesToSkip); }