1616// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
1717// DEALINGS IN THE SOFTWARE.
1818
19+ using System ;
1920using System . Collections . Generic ;
2021using System . Reflection . Metadata ;
2122using System . Reflection . Metadata . Ecma335 ;
@@ -38,7 +39,7 @@ public FieldMarshalTableTreeNode(PEFile module)
3839
3940 public override object Icon => Images . Literal ;
4041
41- public unsafe override bool View ( ViewModels . TabPageModel tabPage )
42+ public override bool View ( ViewModels . TabPageModel tabPage )
4243 {
4344 tabPage . Title = Text . ToString ( ) ;
4445 tabPage . SupportsLanguageSwitching = false ;
@@ -50,7 +51,7 @@ public unsafe override bool View(ViewModels.TabPageModel tabPage)
5051 FieldMarshalEntry scrollTargetEntry = default ;
5152
5253 var length = metadata . GetTableRowCount ( TableIndex . FieldMarshal ) ;
53- byte * ptr = metadata . MetadataPointer ;
54+ ReadOnlySpan < byte > ptr = metadata . AsReadOnlySpan ( ) ;
5455 int metadataOffset = module . Reader . PEHeaders . MetadataStartOffset ;
5556 for ( int rid = 1 ; rid <= length ; rid ++ )
5657 {
@@ -79,14 +80,14 @@ readonly struct FieldMarshal
7980 public readonly BlobHandle NativeType ;
8081 public readonly EntityHandle Parent ;
8182
82- public unsafe FieldMarshal ( byte * ptr , int blobHeapSize , int hasFieldMarshalRefSize )
83+ public FieldMarshal ( ReadOnlySpan < byte > ptr , int blobHeapSize , int hasFieldMarshalRefSize )
8384 {
84- Parent = Helpers . FromHasFieldMarshalTag ( ( uint ) Helpers . GetValue ( ptr , hasFieldMarshalRefSize ) ) ;
85- NativeType = MetadataTokens . BlobHandle ( Helpers . GetValue ( ptr + hasFieldMarshalRefSize , blobHeapSize ) ) ;
85+ Parent = Helpers . FromHasFieldMarshalTag ( ( uint ) Helpers . GetValueLittleEndian ( ptr , hasFieldMarshalRefSize ) ) ;
86+ NativeType = MetadataTokens . BlobHandle ( Helpers . GetValueLittleEndian ( ptr . Slice ( hasFieldMarshalRefSize , blobHeapSize ) ) ) ;
8687 }
8788 }
8889
89- unsafe struct FieldMarshalEntry
90+ struct FieldMarshalEntry
9091 {
9192 readonly PEFile module ;
9293 readonly MetadataReader metadata ;
@@ -112,7 +113,7 @@ public void OnParentClick()
112113 [ ColumnInfo ( "X8" , Kind = ColumnKind . HeapOffset ) ]
113114 public int NativeType => MetadataTokens . GetHeapOffset ( fieldMarshal . NativeType ) ;
114115
115- public FieldMarshalEntry ( PEFile module , byte * ptr , int metadataOffset , int row )
116+ public FieldMarshalEntry ( PEFile module , ReadOnlySpan < byte > ptr , int metadataOffset , int row )
116117 {
117118 this . module = module ;
118119 this . metadata = module . Metadata ;
@@ -122,7 +123,7 @@ public FieldMarshalEntry(PEFile module, byte* ptr, int metadataOffset, int row)
122123 this . Offset = metadataOffset + rowOffset ;
123124 int hasFieldMarshalRefSize = metadata . ComputeCodedTokenSize ( 32768 , TableMask . Field | TableMask . Param ) ;
124125 int blobHeapSize = metadata . GetHeapSize ( HeapIndex . Blob ) < ushort . MaxValue ? 2 : 4 ;
125- this . fieldMarshal = new FieldMarshal ( ptr + rowOffset , blobHeapSize , hasFieldMarshalRefSize ) ;
126+ this . fieldMarshal = new FieldMarshal ( ptr . Slice ( rowOffset ) , blobHeapSize , hasFieldMarshalRefSize ) ;
126127 this . parentTooltip = null ;
127128 }
128129 }
0 commit comments