x) Recording deserialization

This commit is contained in:
Marc Hernandez 2024-05-02 19:37:26 -07:00
parent 0c37db10b5
commit ff28a94131
2 changed files with 56 additions and 4 deletions

View File

@ -67,8 +67,16 @@ public interface Meta
public interface Imm
{
public Meta Meta { get; }
public object Record( string reason = "",
[CallerMemberName] string dbgName = "",
[CallerFilePath] string dbgPath = "",
[CallerLineNumber] int dbgLine = 0
);
}
//[lib.Ser( Types = lib.Types.None )]
public record class Versioned<T> : Imm
where T : Versioned<T>
@ -93,6 +101,18 @@ public record class Versioned<T> : Imm
MetaStorage = meta;
}
virtual public T Record(
string reason = "",
[CallerMemberName] string dbgName = "",
[CallerFilePath] string dbgPath = "",
[CallerLineNumber] int dbgLine = 0
)
{
return Process( t => t, reason );
}
protected MetaData MetaStorage = new();
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
@ -139,10 +159,14 @@ public record class Versioned<T> : Imm
}
};
}
object Imm.Record( string reason, string dbgName, string dbgPath, int dbgLine ) => Record( reason, dbgName, dbgPath, dbgLine );
//public object Record( string reason = "", [CallerMemberName] string dbgName = "", [CallerFilePath] string dbgPath = "", [CallerLineNumber] int dbgLine = 0 ) => Recorded( );
}
//[lib.Ser( Types = lib.Types.None )]
public record class Recorded<T> : Versioned<T>
public record class Recorded<T> : Versioned<T>, imm.Imm
where T : Recorded<T>
{
@ -171,7 +195,7 @@ public record class Recorded<T> : Versioned<T>
new public MetaData Meta => MetaStorage as MetaData;
virtual public T Record(
override public T Record(
string reason = "",
[CallerMemberName] string dbgName = "",
[CallerFilePath] string dbgPath = "",
@ -230,7 +254,7 @@ public record class Recorded<T> : Versioned<T>
}
}
public record class Timed<T> : Recorded<T>
public record class Timed<T> : Recorded<T>, imm.Imm
where T : Timed<T>
{

View File

@ -12,6 +12,7 @@ using System.Diagnostics;
using System.Linq;
using System.Collections.Immutable;
using System.Net.Sockets;
/*
@ -177,9 +178,18 @@ namespace lib
#region Deserialize
private static FormatterConverter s_conv = new();
private string fromStr = "";
void SetFromStr( Stream stream )
{
fromStr = stream.ToString();
fromStr = string.IsNullOrWhiteSpace(fromStr) ? (stream as FileStream).Name : fromStr;
fromStr = string.IsNullOrWhiteSpace(fromStr) ? (stream as NetworkStream).Socket.RemoteEndPoint.ToString() : fromStr;
}
public object Deserialize( Stream stream )
{
SetFromStr( stream );
return DeserializeKnownType( stream, null );
}
@ -188,6 +198,8 @@ namespace lib
public object DeserializeKnownType( Stream stream, Type t )
{
SetFromStr( stream );
XmlTextReader reader = new( stream );
object obj = Deserialize( reader, t );
@ -214,6 +226,8 @@ namespace lib
public void DeserializeInto<T>( Stream stream, T obj )
{
SetFromStr( stream );
XmlTextReader reader = new( stream );
reader.Read();
@ -497,8 +511,10 @@ namespace lib
return obj;
}
private void HydrateObjectOfNarrowType( XmlElement elem, MemberInfo mi, Type narrowType, object obj )
private object HydrateObjectOfNarrowType( XmlElement elem, MemberInfo mi, Type narrowType, object obj )
{
var isImm = typeof(imm.Imm).IsAssignableFrom( narrowType );
XmlNodeList allChildren = elem.ChildNodes;
bool filterFields, filterProps, doImpls, doFields, doProps;
@ -618,6 +634,18 @@ namespace lib
}
}
}
if(!isImm)
{
return obj;
}
else
{
var imm = obj as imm.Imm;
var newObj = imm.Record( $"From XML {fromStr}:{elem.ParentNode?.Name}{elem.Name}" );
return newObj;
}
}
private static bool FilterField( bool filterFields, bool doImpls, HashSet<string> whitelistFields, MemberInfo mi, string name )