Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Comparer{T}" /> class.
        /// </summary>
        /// <param name="settings">Comparison Settings.</param>
        /// <param name="parentComparer">Parent Comparer. Is used to copy DefaultValueComparer and Overrides. Null by default.</param>
        /// <param name="factory">Factory to create comparers in case of some members of the objects will need it.</param>
        public Comparer(ComparisonSettings settings = null, BaseComparer parentComparer = null, IComparersFactory factory = null)
            : base(settings, parentComparer, factory)
        {
            var properties = typeof(T).GetTypeInfo().GetProperties().Where(p =>
                                                                           p.CanRead &&
                                                                           p.GetGetMethod(true).IsPublic &&
                                                                           p.GetGetMethod(true).GetParameters().Length == 0 &&
                                                                           !p.GetGetMethod(true).IsStatic).ToList();
            var fields = typeof(T).GetTypeInfo().GetFields().Where(f =>
                                                                   f.IsPublic && !f.IsStatic).ToList();

            _members = properties.Union(fields.Cast <MemberInfo>()).ToList();
            _conditionalComparers = new List <IComparerWithCondition>
            {
                new MultidimensionalArraysComparer(Settings, this, Factory),
                new ExpandoObjectComparer(Settings, this, Factory),
                new DynamicObjectComparer(Settings, this, Factory),
                new CompilerGeneratedObjectComparer(Settings, this, Factory),
                new HashSetsComparer(Settings, this, Factory),
                new GenericEnumerablesComparer(Settings, this, Factory),
                new EnumerablesComparer(Settings, this, Factory),
                new TypesComparer(Settings, this, Factory)
            };

            // Additional value comparers
            AddComparerOverride <StringBuilder>(new ToStringComparer <StringBuilder>());
            AddComparerOverride <Uri>(new UriComparer());
        }
Ejemplo n.º 2
0
 protected BaseComparer(ComparisonSettings settings, BaseComparer parentComparer, IComparersFactory factory)
 {
     Factory              = factory ?? new ComparersFactory();
     Settings             = settings ?? new ComparisonSettings();
     DefaultValueComparer = new DefaultValueComparer();
     if (parentComparer != null)
     {
         DefaultValueComparer = parentComparer.DefaultValueComparer;
         OverridesCollection.Merge(parentComparer.OverridesCollection);
     }
 }
Ejemplo n.º 3
0
 protected AbstractComparer(ComparisonSettings settings, BaseComparer parentComparer, IComparersFactory factory)
     : base(settings, parentComparer, factory)
 {
 }
Ejemplo n.º 4
0
 public EnumerablesComparer(ComparisonSettings settings, BaseComparer parentComparer, IComparersFactory factory)
     : base(settings, parentComparer, factory)
 {
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Comparer" /> class.
 /// </summary>
 /// <param name="settings">Comparison Settings.</param>
 /// <param name="parentComparer">Parent Comparer. Is used to copy DefaultValueComparer and Overrides. Null by default.</param>
 /// <param name="factory">Factory to create comparers in case of some members of the objects will need it.</param>
 public Comparer(ComparisonSettings settings = null, BaseComparer parentComparer = null, IComparersFactory factory = null) : base(settings, parentComparer, factory)
 {
 }
 public HashSetsComparer(ComparisonSettings settings, BaseComparer parentComparer, IComparersFactory factory)
     : base(settings, parentComparer, factory)
 {
 }
 public EnumerablesComparer(ComparisonSettings settings, BaseComparer parentComparer, IComparersFactory factory)
     : base(settings, parentComparer, factory)
 {
     _comparer = Factory.GetObjectsComparer <T>(Settings, this);
 }
Ejemplo n.º 8
0
 public HashSetsComparer(ComparisonSettings settings, BaseComparer parentComparer, IComparersFactory factory)
     : base(settings, parentComparer, factory)
 {
     _comparer = new Comparer <T>(Settings, this);
 }
 public MultidimensionalArrayComparer(ComparisonSettings settings, BaseComparer parentComparer, IComparersFactory factory)
     : base(settings, parentComparer, factory)
 {
     _comparer = Factory.GetObjectsComparer <T>(Settings, this);
 }
Ejemplo n.º 10
0
 public MultidimensionalArraysComparer(ComparisonSettings settings, BaseComparer parentComparer,
                                       IComparersFactory factory)
     : base(settings, parentComparer, factory)
 {
 }
 public ExpandoObjectComparer(ComparisonSettings settings, BaseComparer parentComparer, IComparersFactory factory)
     : base(settings, parentComparer, factory)
 {
 }
 /// <summary>
 /// Creates type specific comparer.
 /// </summary>
 /// <param name="type">Type.</param>
 /// <param name="settings">Comparison Settings. Null by default.</param>
 /// <param name="parentComparer">Parent comparer. Null by default.</param>
 /// <returns>Instance of <see cref="IComparer"/>.</returns>
 public IComparer GetObjectsComparer(Type type, ComparisonSettings settings = null, BaseComparer parentComparer = null)
 {
     return(new Comparer(settings, parentComparer, this));
 }
 /// <summary>
 /// Creates type specific comparer.
 /// </summary>
 /// <typeparam name="T">Type.</typeparam>
 /// <param name="settings">Comparison Settings. Null by default.</param>
 /// <param name="parentComparer">Parent comparer. Null by default.</param>
 /// <returns>Instance of <see cref="IComparer{T}"/>.</returns>
 public virtual IComparer <T> GetObjectsComparer <T>(ComparisonSettings settings = null, BaseComparer parentComparer = null)
 {
     return(new Comparer <T>(settings, parentComparer, this));
 }
Ejemplo n.º 14
0
 public CompilerGeneratedObjectComparer(ComparisonSettings settings, BaseComparer parentComparer, IComparersFactory factory)
     : base(settings, parentComparer, factory)
 {
 }