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() { }
|
public Recorded() { }
|
||||||
protected Recorded( Recorded<T> original ) : base( original ) { Meta = original.Meta; }
|
protected Recorded( Recorded<T> original ) : base( original ) { Meta = original.Meta; }
|
||||||
|
|
||||||
public virtual T Process(
|
public override T Process(
|
||||||
Func<T, T> fn,
|
Func<T, T> fn,
|
||||||
string reason = "",
|
string reason = "",
|
||||||
[CallerMemberName] string dbgName = "",
|
[CallerMemberName] string dbgName = "",
|
||||||
@ -261,15 +261,14 @@ public record class Recorded<T> : Versioned<T> where T : Recorded<T>
|
|||||||
if( ReferenceEquals( current, next ) )
|
if( ReferenceEquals( current, next ) )
|
||||||
return current;
|
return current;
|
||||||
|
|
||||||
var newMeta = new Metadata_Recorded
|
var newMeta = current.Meta with {
|
||||||
{
|
|
||||||
Version = current.Meta.Version + 1,
|
Version = current.Meta.Version + 1,
|
||||||
Reason = reason,
|
Reason = reason,
|
||||||
MemberName = dbgName,
|
MemberName = dbgName,
|
||||||
FilePath = dbgPath,
|
FilePath = dbgPath,
|
||||||
LineNumber = dbgLine,
|
LineNumber = dbgLine,
|
||||||
Expression = expStr,
|
Expression = expStr,
|
||||||
OldObject = current
|
OldObject = current,
|
||||||
};
|
};
|
||||||
|
|
||||||
var newVersion = next with { Meta = newMeta, OnChange = current.OnChange };
|
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 = "",
|
[CallerMemberName] string dbgMethod = "",
|
||||||
[CallerFilePath] string dbgPath = "",
|
[CallerFilePath] string dbgPath = "",
|
||||||
[CallerLineNumber] int dbgLine = 0,
|
[CallerLineNumber] int dbgLine = 0,
|
||||||
[CallerArgumentExpression( "fn" )] string dbgExpression = "" )
|
[CallerArgumentExpression( "fn" )] string dbgExpStr = "" )
|
||||||
{
|
{
|
||||||
var current = (T)this;
|
var current = (T)this;
|
||||||
var next = fn( current );
|
var next = fn( current );
|
||||||
@ -316,6 +315,7 @@ public record class Timed<T> : Recorded<T> where T : Timed<T>
|
|||||||
if( ReferenceEquals( current, next ) )
|
if( ReferenceEquals( current, next ) )
|
||||||
return current;
|
return current;
|
||||||
|
|
||||||
|
/*
|
||||||
var newMeta = new Metadata_Timed
|
var newMeta = new Metadata_Timed
|
||||||
{
|
{
|
||||||
Version = current.Meta.Version + 1,
|
Version = current.Meta.Version + 1,
|
||||||
@ -328,9 +328,22 @@ public record class Timed<T> : Recorded<T> where T : Timed<T>
|
|||||||
CreatedAt = current.Meta.CreatedAt,
|
CreatedAt = current.Meta.CreatedAt,
|
||||||
TouchedAt = DateTime.UtcNow
|
TouchedAt = DateTime.UtcNow
|
||||||
};
|
};
|
||||||
|
*/
|
||||||
|
|
||||||
var currentTimedMeta = current.Meta;
|
var newMeta = current.Meta with
|
||||||
var newVersion = next with { Meta = newMeta, OnChange = current.OnChange };
|
{
|
||||||
|
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 );
|
newVersion.OnChange( current, newVersion );
|
||||||
return newVersion;
|
return newVersion;
|
||||||
}
|
}
|
||||||
@ -345,6 +358,7 @@ public record class Timed<T> : Recorded<T> where T : Timed<T>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
public static class TimedExt
|
public static class TimedExt
|
||||||
{
|
{
|
||||||
public static T Process<T>(
|
public static T Process<T>(
|
||||||
@ -361,3 +375,4 @@ public static class TimedExt
|
|||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
@ -1,4 +1,4 @@
|
|||||||
#nullable enable
|
//#nullable enable
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
@ -42,7 +42,10 @@ public static class iu
|
|||||||
return obj;
|
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>
|
// No specific Process needed for Timed, as it's caught by Recorded<T>
|
||||||
// and its Process override handles the timing.
|
// and its Process override handles the timing.
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user