-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactoring ObjectSpace(s) to support Persistence Ignorance (PI)
- Loading branch information
1 parent
57d53d6
commit 8827b75
Showing
27 changed files
with
982 additions
and
740 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System.ComponentModel; | ||
|
||
namespace Hydrogen.Generators { | ||
|
||
public interface IObjectSpaceObject : INotifyPropertyChanging, INotifyPropertyChanged { | ||
bool Dirty { get; set; } | ||
} | ||
|
||
public class Class1 : INotifyPropertyChanging, INotifyPropertyChanged { | ||
|
||
public event PropertyChangingEventHandler? PropertyChanging; | ||
public event PropertyChangedEventHandler? PropertyChanged; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using System; | ||
using Hydrogen.Mapping; | ||
|
||
namespace Hydrogen.ObjectSpaces; | ||
|
||
internal class ObjectChangeTracker { | ||
|
||
public ObjectChangeTracker() { | ||
HasChanged = _ => false;; | ||
SetChanged = (_, _) => { }; | ||
SupportsChangeTracking = false; | ||
} | ||
|
||
public ObjectChangeTracker(Member member) | ||
: this(Guard.EnsureCast<PropertyMember>(member, $"Must be a {nameof(PropertyMember)}")) { | ||
} | ||
|
||
public ObjectChangeTracker(PropertyMember member) { | ||
Guard.ArgumentNotNull(member, nameof(member)); | ||
Guard.Ensure(member.CanRead, "Member must have public getter"); | ||
Guard.Ensure(member.CanWrite, "Member must have public setter"); | ||
Guard.Ensure(member.PropertyType == typeof(bool), "Member must be of type bool"); | ||
HasChanged = obj => (bool)member.GetValue(obj); | ||
SetChanged = (obj, val) => member.SetValue(obj, val); | ||
SupportsChangeTracking = true; | ||
} | ||
|
||
public ObjectChangeTracker(Func<object, bool> hasChanged, Action<object, bool> setChanged) { | ||
Guard.ArgumentNotNull(hasChanged, nameof(hasChanged)); | ||
Guard.ArgumentNotNull(setChanged, nameof(setChanged)); | ||
HasChanged = hasChanged; | ||
SetChanged = setChanged; | ||
SupportsChangeTracking = true; | ||
} | ||
|
||
public bool SupportsChangeTracking { get; } | ||
|
||
public Func<object, bool> HasChanged { get; } | ||
|
||
public Action<object, bool> SetChanged { get; } | ||
|
||
public static ObjectChangeTracker Default { get; } = new (); | ||
|
||
} |
Oops, something went wrong.