diff --git a/imm/Imm.cs b/imm/Imm.cs index 56a000d..8040bd7 100644 --- a/imm/Imm.cs +++ b/imm/Imm.cs @@ -63,10 +63,10 @@ public interface Obj : Obj where T : Obj string reason = "Processed", [CallerMemberName] string dbgName = "", [CallerFilePath] string dbgPath = "", - [CallerLineNumber] int dbgLine = 0 , - [CallerArgumentExpression("fn")] string expStr = "" ); + [CallerLineNumber] int dbgLine = 0, + [CallerArgumentExpression( "fn" )] string expStr = "" ); + - /// /// Creates a new version without a functional change using basic processing. /// Uses 'new' to provide a type-safe return. @@ -128,8 +128,8 @@ public interface RecordedMeta : VersionedMeta { public string MemberName { get; } public string FilePath { get; } - public int LineNumber { get; } - public string Expression { get; } + public int LineNumber { get; } + public string Expression { get; } } @@ -183,7 +183,7 @@ public record class Versioned : Obj where T : Versioned public Versioned() { } protected Versioned( Versioned original ) { - OnChange = original.OnChange; + OnChange = original.OnChange; Meta = original.Meta; } @@ -192,8 +192,8 @@ public record class Versioned : Obj where T : Versioned string reason = "Processed", [CallerMemberName] string dbgName = "", [CallerFilePath] string dbgPath = "", - [CallerLineNumber] int dbgLine = 0 , - [CallerArgumentExpression("fn")] string expStr = "" ) + [CallerLineNumber] int dbgLine = 0, + [CallerArgumentExpression( "fn" )] string expStr = "" ) { var current = (T)this; var next = fn( current ); @@ -245,7 +245,7 @@ public record class Recorded : Versioned where T : Recorded //Metadata_Versioned Obj.Meta => this.Meta; public Recorded() { } - protected Recorded(Recorded original) : base(original) { Meta = original.Meta; } + protected Recorded( Recorded original ) : base( original ) { Meta = original.Meta; } public virtual T Process( Func fn, @@ -253,12 +253,13 @@ public record class Recorded : Versioned where T : Recorded [CallerMemberName] string dbgName = "", [CallerFilePath] string dbgPath = "", [CallerLineNumber] int dbgLine = 0, - [CallerArgumentExpression("fn")] string expStr = "") + [CallerArgumentExpression( "fn" )] string expStr = "" ) { var current = (T)this; - var next = fn(current); + var next = fn( current ); - if (ReferenceEquals(current, next)) return current; + if( ReferenceEquals( current, next ) ) + return current; var newMeta = new Metadata_Recorded { @@ -272,7 +273,7 @@ public record class Recorded : Versioned where T : Recorded }; var newVersion = next with { Meta = newMeta, OnChange = current.OnChange }; - newVersion.OnChange(current, newVersion); + newVersion.OnChange( current, newVersion ); return newVersion; } @@ -280,9 +281,9 @@ public record class Recorded : Versioned where T : Recorded string reason = "Recorded", [CallerMemberName] string dbgName = "", [CallerFilePath] string dbgPath = "", - [CallerLineNumber] int dbgLine = 0) + [CallerLineNumber] int dbgLine = 0 ) { - return Process(t => t, reason, dbgName, dbgPath, dbgLine ); + return Process( t => t, reason, dbgName, dbgPath, dbgLine ); } } @@ -294,11 +295,11 @@ public record class Timed : Recorded where T : Timed { new public Metadata_Timed Meta { get; init; } = new(); //Metadata_Versioned Obj.Meta => this.Meta; - public TimeSpan SinceLastTouch => Meta.TouchedAt - (Old?.Meta as Metadata_Timed)?.TouchedAt ?? TimeSpan.Zero; + public TimeSpan SinceLastTouch => Meta.TouchedAt - ( Old?.Meta as Metadata_Timed )?.TouchedAt ?? TimeSpan.Zero; public TimeSpan TotalAge => Meta.TouchedAt - Meta.CreatedAt; public Timed() { } - protected Timed(Timed original) : base(original) { Meta = original.Meta; } + protected Timed( Timed original ) : base( original ) { Meta = original.Meta; } public override T Process( @@ -324,7 +325,7 @@ public record class Timed : Recorded where T : Timed LineNumber = dbgLine, Expression = dbgExpression, OldObject = current, - CreatedAt = DateTime.UtcNow, + CreatedAt = current.Meta.CreatedAt, TouchedAt = DateTime.UtcNow }; @@ -338,9 +339,9 @@ public record class Timed : Recorded where T : Timed string reason = "Recorded", [CallerMemberName] string dbgName = "", [CallerFilePath] string dbgPath = "", - [CallerLineNumber] int dbgLine = 0) + [CallerLineNumber] int dbgLine = 0 ) { - return Process(t => t, reason, dbgName, dbgPath, dbgLine ); + return Process( t => t, reason, dbgName, dbgPath, dbgLine ); } } @@ -354,8 +355,7 @@ public static class TimedExt [CallerFilePath] string dbgPath = "", [CallerLineNumber] int dbgLine = 0, [CallerArgumentExpression( "fn" )] string dbgExpression = "" - ) - where T : imm.Timed + ) where T : imm.Timed { obj = obj.Process( fn, reason, dbgName, dbgPath, dbgLine, dbgExpression ); return obj;