diff --git a/imm/Imm.cs b/imm/Imm.cs index 8040bd7..efacaec 100644 --- a/imm/Imm.cs +++ b/imm/Imm.cs @@ -247,7 +247,7 @@ public record class Recorded : Versioned where T : Recorded public Recorded() { } protected Recorded( Recorded original ) : base( original ) { Meta = original.Meta; } - public virtual T Process( + public override T Process( Func fn, string reason = "", [CallerMemberName] string dbgName = "", @@ -261,15 +261,14 @@ public record class Recorded : Versioned where T : Recorded if( ReferenceEquals( current, next ) ) return current; - var newMeta = new Metadata_Recorded - { + var newMeta = current.Meta with { Version = current.Meta.Version + 1, Reason = reason, MemberName = dbgName, FilePath = dbgPath, LineNumber = dbgLine, Expression = expStr, - OldObject = current + OldObject = current, }; var newVersion = next with { Meta = newMeta, OnChange = current.OnChange }; @@ -308,7 +307,7 @@ public record class Timed : Recorded where T : Timed [CallerMemberName] string dbgMethod = "", [CallerFilePath] string dbgPath = "", [CallerLineNumber] int dbgLine = 0, - [CallerArgumentExpression( "fn" )] string dbgExpression = "" ) + [CallerArgumentExpression( "fn" )] string dbgExpStr = "" ) { var current = (T)this; var next = fn( current ); @@ -316,6 +315,7 @@ public record class Timed : Recorded where T : Timed if( ReferenceEquals( current, next ) ) return current; + /* var newMeta = new Metadata_Timed { Version = current.Meta.Version + 1, @@ -328,9 +328,22 @@ public record class Timed : Recorded where T : Timed CreatedAt = current.Meta.CreatedAt, TouchedAt = DateTime.UtcNow }; + */ - var currentTimedMeta = current.Meta; - var newVersion = next with { Meta = newMeta, OnChange = current.OnChange }; + var newMeta = current.Meta with + { + Version = current.Meta.Version + 1, + Reason = reason, + MemberName = dbgMethod, + FilePath = dbgPath, + LineNumber = dbgLine, + Expression = dbgExpStr, + OldObject = current, + TouchedAt = DateTime.UtcNow + }; + + // Testing: Shouldnt need the OnChange + var newVersion = next with { Meta = newMeta }; newVersion.OnChange( current, newVersion ); return newVersion; } @@ -345,6 +358,7 @@ public record class Timed : Recorded where T : Timed } } +/* public static class TimedExt { public static T Process( @@ -361,3 +375,4 @@ public static class TimedExt return obj; } } +*/ \ No newline at end of file diff --git a/imm/iu.cs b/imm/iu.cs index 0b8473f..0e8baed 100644 --- a/imm/iu.cs +++ b/imm/iu.cs @@ -1,4 +1,4 @@ -#nullable enable +//#nullable enable using System; using System.Runtime.CompilerServices; @@ -42,7 +42,10 @@ public static class iu return obj; } - + public static string LogDiff( T cur, T old, [CallerArgumentExpression( "cur" )] string dbgExpCur = "", [CallerArgumentExpression( "old" )] string dbgExpOld = "" ) + { + return $"{dbgExpCur} changed from {old} to {cur}"; + } // No specific Process needed for Timed, as it's caught by Recorded // and its Process override handles the timing.