-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Recorder_Enumerator: Support OfType, Cast, and ArrayEnumerator.
- Loading branch information
Ben Rog-Wilhelm
committed
Oct 6, 2023
1 parent
baffd99
commit 6c03141
Showing
3 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
namespace Dec.RecorderEnumerator | ||
{ | ||
using System; | ||
using System.Reflection; | ||
|
||
public class System_ArrayEnumerator_Converter : ConverterFactoryDynamic | ||
{ | ||
internal static Type RelevantType = typeof(System.Array).Assembly.GetType("System.ArrayEnumerator"); | ||
|
||
internal FieldInfo field_Array = RelevantType.GetPrivateFieldInHierarchy("_array"); | ||
internal FieldInfo field_Index = RelevantType.GetPrivateFieldInHierarchy("_index"); | ||
|
||
public override void Write(object input, Recorder recorder) | ||
{ | ||
recorder.Shared().RecordPrivate(input, field_Array, "array"); | ||
|
||
// I assume this is an IntPtr just to avoid taking up more space on 32-bit systems | ||
// but, seriously guys, wat | ||
IntPtr intPtr = (IntPtr)field_Index.GetValue(input); | ||
long intPtrValue = intPtr.ToInt64(); | ||
recorder.Record(ref intPtrValue, "index"); | ||
} | ||
|
||
public override object Create(Recorder recorder) | ||
{ | ||
// I am frankly bewildered as to why Activator.CreateInstance() doesn't work here. | ||
var cs = RelevantType.GetConstructors(BindingFlags.Instance | BindingFlags.NonPublic); | ||
return cs[0].Invoke(new object[] { null }); | ||
} | ||
|
||
public override void Read(ref object input, Recorder recorder) | ||
{ | ||
recorder.Shared().RecordPrivate(input, field_Array, "array"); | ||
|
||
long intPtrValue = 0; | ||
recorder.Record(ref intPtrValue, "index"); | ||
IntPtr intPtr = new IntPtr(intPtrValue); | ||
field_Index.SetValue(input, intPtr); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters