/// <summary> /// Gets the comparison strategy for the current XML node. /// </summary> /// <param name="reader">The XML reader.</param> private ObjectGraphComparisonStrategy GetStrategy(XmlReader reader) { ObjectGraphComparisonStrategy strategy = null; if (reader.HasAttributes) { for (int i = 0; i < reader.AttributeCount; i++) { reader.MoveToAttribute(i); if (string.Equals( reader.Name, ComparisonStrategyXmlAttribute, StringComparison.OrdinalIgnoreCase)) { if (strategy != null) { throw new XmlException("XML node can have only one comparison strategy attribute"); } TryFindStrategy(reader.Value, out strategy); } } reader.MoveToElement(); } return(strategy); }
/// <summary> /// Tries to find the strategy by its name. /// </summary> private bool TryFindStrategy(string name, out ObjectGraphComparisonStrategy strategy) { Debug.Assert(name != null); if (string.IsNullOrEmpty(name.Trim())) { throw new XmlException("Comparison strategy name is empty or whitespaces."); } if (!strategies.TryGetValue(name, out strategy)) { if (ThrowExceptionOnUnknownComparisonStrategy) { throw new XmlException( string.Format("Comparison strategy with an unknown name is found: {0}.", name)); } return(false); } return(true); }
/// <summary> /// Gets the name of the strategy. /// </summary> private static string GetStrategyName(ObjectGraphComparisonStrategy strategy) { Debug.Assert(strategy != null); return(strategy.GetType().Name); }