예제 #1
0
    public Comparer(myClass x, myClass y)
    {
        var xProperties = x.GetType().GetProperties();
        var yProperties = y.GetType().GetProperties();

        var xPropertiesValues = xProperties.Select(pi => pi.GetValue(x, null));
        var yPropertiesValues = yProperties.Select(pi => pi.GetValue(y, null));

        AreEqual = xPropertiesValues.SequenceEqual(yPropertiesValues);
    }
    static void Main(string[] args)
    {
        myClass currentObj = new myClass()
        {
            Text = "test", Value = 5
        };
        myClass updatedObj = new myClass()
        {
            Text = "test 2 ", Value = 6
        };
        Type cType      = currentObj.GetType();
        var  fieldInfos = cType.GetFields();

        foreach (var fieldInfo in fieldInfos)
        {
            if (fieldInfo.GetValue(updatedObj) != null)
            {
                fieldInfo.SetValue(currentObj, fieldInfo.GetValue(updatedObj));
            }
        }
    }