Skip to content

Commit f59b152

Browse files
committed
Added IgnoreDifferences attribute
1 parent ee6eae7 commit f59b152

4 files changed

Lines changed: 19 additions & 5 deletions

File tree

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ dotnet add package ObjDiff
3333

3434
## Current Limitations
3535

36-
This library is still in an early stage of development and so it lacks some features that similar libraries can offer:
37-
3836
* Only allows to compare objects of the same type
3937
* Only public properties are compared
4038

@@ -102,6 +100,13 @@ public class CompareOptions
102100
}
103101
```
104102

103+
### Ignoring Properties
104+
105+
Any property marked with the `IgnoreDifferences` attribute will always be skipped during the comparison process, no matter
106+
the actual value of the `IgnoredAttributes` property if `CompareOptions` is used.
107+
108+
The usage of this attribute
109+
105110
### Patching
106111

107112
Once we have the differences between two objects, we can apply them (patch) to the original object being compared. After patching it, both objects should be equivalent.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using System;
2+
3+
namespace ObjDiff
4+
{
5+
[AttributeUsage(AttributeTargets.Property)]
6+
public class IgnoreDifferencesAttribute : Attribute
7+
{
8+
}
9+
}

src/ObjDiff/ObjDiff.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ private static IEnumerable<Difference> Diff<T>(T left, T right, CompareOptions c
144144
compareOptions = new CompareOptions();
145145

146146
var applicableProperties = left.GetType().GetProperties().Where(p => !compareOptions.IgnoredProperties.Contains(p.Name) &&
147-
!p.GetCustomAttributes(false).Any(x => compareOptions.IgnoredAttributes.Contains(x.GetType().Name)));
147+
!p.GetCustomAttributes(false).Any(x => x.GetType() == typeof(IgnoreDifferencesAttribute) || compareOptions.IgnoredAttributes.Contains(x.GetType().Name)));
148148

149149
foreach (var property in applicableProperties)
150150
{

src/ObjDiff/ObjDiff.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
<Authors>Israel Gómez de Celis González</Authors>
1313
<Description>A C# .NET Standard library that allows to obtain the differences between two objects and, optionally, patch the first object with these differences so it becomes equal to the second one.</Description>
1414
<Copyright>Copyright (c) 2021 Israel Gómez de Celis González</Copyright>
15-
<Version>1.2.0</Version>
16-
<PackageReleaseNotes>Added method MakeEqual as a shortcut to call Diff followed by Patch.</PackageReleaseNotes>
15+
<Version>1.3.0</Version>
16+
<PackageReleaseNotes>New IgnoreDifferences attribute. Any property marked with this attribute will be always ignored.</PackageReleaseNotes>
1717
</PropertyGroup>
1818

1919
<ItemGroup>

0 commit comments

Comments
 (0)