Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9108547
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T02:50:02+00:00 2026-06-17T02:50:02+00:00

Let’s say i have such structure public class Form { #region Public Properties public

  • 0

Let’s say i have such structure

public class Form
{
    #region Public Properties

    public List<Field> Fields { get; set; }

    public string Id { get; set; }

    public string Name { get; set; }

    public string Version { get; set; }

    public int Revision { get; set; }

    #endregion
}

So the Form class contains the list of fields, let’s say that the Field itself is represented with such structure

public class Field
{
    #region Public Properties

    public string DisplayName { get; set; }

    public List<Field> Fields { get; set; }

    public string Id { get; set; }

    public FieldKind Type { get; set; }

    public FieldType FieldType { get; set; }

    #endregion
}

The Field is basically composite structure, each Field contains the list of child fields. So the structure is hierarchical. Also Field has reference to the FieldType class.

public class FieldType
{
    #region Public Properties

    public DataType DataType { get; set; }

    public string DisplayName { get; set; }

    public string Id { get; set; }

    #endregion
}

And at the end we have reference to the DataType

public class DataType
{
    #region Public Properties

    public string BaseType { get; set; }

    public string Id { get; set; }

    public string Name { get; set; }

    public List<Restriction> Restrictions { get; set; }

    #endregion
}

What I want to achieve is to get the difference of such complex structure, let’s say if I have some sort of Comparer it will give me structured difference for the whole form as one class, let’s say DifferenceResult. When I said structured difference I mean that it should be something like that.

  1. Difference for the Form fields (output Form has difference in Version field (different color)
  2. Differences for the Fields collection, including the hierarchy of the fields to the edited field
  3. Same behavior for the FieldType and DataType
  4. Detect removing and adding the Field into the Form (so probably each Difference will have a Type)

What I have right now. I started with generic approach and tried to use ReflectionComparer implementing IEqualityComparer interface

public bool Equals(T x, T y)
{
    var type = typeof(T);

    if (typeof(IEquatable<T>).IsAssignableFrom(type))
    {
        return EqualityComparer<T>.Default.Equals(x, y);
    }

    var enumerableType = type.GetInterface(typeof(IEnumerable<>).FullName);

    if (enumerableType != null)
    {
        var elementType = enumerableType.GetGenericArguments()[0];
        var elementComparerType = typeof(DifferenceComparer<>).MakeGenericType(elementType);

        var elementComparer = Activator.CreateInstance(elementComparerType, new object[] { _foundDifferenceCallback, _existedDifference });

        return (bool)typeof(Enumerable).GetGenericMethod("SequenceEqual", new[] { typeof(IEnumerable<>), typeof(IEnumerable<>), typeof(IEqualityComparer<>) }).MakeGenericMethod(elementType).Invoke(null, new[] { x, y, elementComparer });
    }

    foreach (var propertyInfo in type.GetProperties())
    {
        var leftValue = propertyInfo.GetValue(x);
        var rightValue = propertyInfo.GetValue(y);

        if (leftValue != null)
        {
            var propertyComparerType = typeof(DifferenceComparer<>).MakeGenericType(propertyInfo.PropertyType);

            var propertyComparer = Activator.CreateInstance(propertyComparerType, new object[] {_foundDifferenceCallback, _existedDifference});

            if (!((bool)typeof(IEqualityComparer<>).MakeGenericType(propertyInfo.PropertyType)
                .GetMethod("Equals")
                .Invoke(propertyComparer, new object[] { leftValue, rightValue })))
            {
                // Create and publish the difference with its Type
            }
        }
        else
        {
            if (!Equals(leftValue, rightValue))
            {
                // Create and publish the difference with its Type
            }
        }
    }

    //return true if no differences are found
}

And Difference class

public struct Difference
{
    public readonly string Property;

    public readonly DifferenceType Type;

    public readonly IExtractionable Expected;

    public readonly IExtractionable Actual;
}

But probably it’s not the way I want to go, because I should compare Field more precisely taking in consideration that each Field has Id, which can be different for different forms as well and I want to take more control of the comparing process. For me it sounds more like a diff tool.

So I am looking for good pattern and pretty good structure to publish the Difference to the client code, which can easily visualize it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T02:50:04+00:00Added an answer on June 17, 2026 at 2:50 am

    After investigating a bit and comparing different resources I implemented such algorithm.

    1. Take your object and construct the graph (using .GetType().GetProperties(), adding each property as a child node of you root node. The key of the node will be the property name.
    2. Go recursively if you meet properties of any custom type or IEnumerable.
    3. Create graph comparer and simple compare two graphs

    Later I will publish my code and update the answer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say that I have classes like this: public class Parent { public int
Let's say you have a class, with certain properties, and that you tried your
Let's say I have the following class: public class Test<E> { public boolean sameClassAs(Object
Let me explain best with an example. Say you have node class that can
Let's say I have a sortable list like this: $(.song-list).sortable({ handle : '.pos_handle', axis
Let's say I have pseudocode like this: main() { BOOL b = get_bool_from_environment(); //get
Let's say for a moment that I have the following module in python: class
Let's say we have this simple class: class example { bool m_isCanceled; example() :
Let me try again.. I have two classes: class OrdenO { public int id_orden_O
Let's say I have one class User, and it has a property of type

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.