Fix some immutability stuff. Better partial Guid logging
This commit is contained in:
parent
307a0b8cdc
commit
bbef15138c
29
imm/Imm.cs
29
imm/Imm.cs
@ -247,7 +247,7 @@ public record class Recorded<T> : Versioned<T> where T : Recorded<T>
|
||||
public Recorded() { }
|
||||
protected Recorded( Recorded<T> original ) : base( original ) { Meta = original.Meta; }
|
||||
|
||||
public virtual T Process(
|
||||
public override T Process(
|
||||
Func<T, T> fn,
|
||||
string reason = "",
|
||||
[CallerMemberName] string dbgName = "",
|
||||
@ -261,15 +261,14 @@ public record class Recorded<T> : Versioned<T> where T : Recorded<T>
|
||||
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<T> : Recorded<T> where T : Timed<T>
|
||||
[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<T> : Recorded<T> where T : Timed<T>
|
||||
if( ReferenceEquals( current, next ) )
|
||||
return current;
|
||||
|
||||
/*
|
||||
var newMeta = new Metadata_Timed
|
||||
{
|
||||
Version = current.Meta.Version + 1,
|
||||
@ -328,9 +328,22 @@ public record class Timed<T> : Recorded<T> where T : Timed<T>
|
||||
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<T> : Recorded<T> where T : Timed<T>
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
public static class TimedExt
|
||||
{
|
||||
public static T Process<T>(
|
||||
@ -361,3 +375,4 @@ public static class TimedExt
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
*/
|
||||
@ -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>( 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<T>
|
||||
// and its Process override handles the timing.
|
||||
|
||||
Loading…
Reference in New Issue
Block a user