public void PropertyMap_WhenCreated_OffsetIsMovedOn() { byte[] contents = new byte[4]; Offset offset = 0; IIndexDetails indexDetails = IndexHelper.CreateIndexDetails(2); PropertyMapMetadataTableRow row = new PropertyMapMetadataTableRow(contents, offset, indexDetails); Assert.AreEqual(4, offset.Current); }
public int Compare(PropertyMapMetadataTableRow x, PropertyMapMetadataTableRow y) { if (x.Parent < y.Parent) { return(-1); } if (x.Parent == y.Parent) { return(0); } return(1); }
public void PropertyMap_WhenCreated_FieldsAreReadCorrectly() { byte[] contents = new byte[] { 0x01, 0x00, 0x02, 0x00 }; IIndexDetails indexDetails = IndexHelper.CreateIndexDetails(2); Offset offset = 0; PropertyMapMetadataTableRow row = new PropertyMapMetadataTableRow(contents, offset, indexDetails); Assert.AreEqual(1, row.Parent.Value); Assert.AreEqual(2, row.PropertyList.Value); }
public PropertyMapEntry(MetadataDirectory directory, PropertyMapMetadataTableRow row) { this.FileOffset = string.Format("0x{0:x}", row.FileOffset); this.Parent = row.Parent.Value.ToString(); this.PropertyList = row.PropertyList.Value.ToString(); }
private void LoadProperties() { // Check if we have a property map and then find the property map for the current type // if it exists. if (!_metadataStream.Tables.ContainsKey(MetadataTables.PropertyMap)) { return; } // TODO: The metadata tables are in order, we should use a sorted search algorithm to // find elements we need. int startPropertyList = -1; int endPropertyList = -1; PropertyMapMetadataTableRow searchFor = new PropertyMapMetadataTableRow(); searchFor.Parent = _indexInMetadataTable; int mapIndex = Array.BinarySearch(_metadataStream.Tables[MetadataTables.PropertyMap], searchFor, new PropertyMapComparer() ); if (mapIndex >= 0) { startPropertyList = ((PropertyMapMetadataTableRow)_metadataStream.Tables[MetadataTables.PropertyMap][mapIndex]).PropertyList; if (mapIndex < _metadataStream.Tables[MetadataTables.PropertyMap].Length - 1) { endPropertyList = ((PropertyMapMetadataTableRow)_metadataStream.Tables[MetadataTables.PropertyMap][mapIndex + 1]).PropertyList - 1; } else { endPropertyList = _metadataStream.Tables[MetadataTables.Property].Length; } } // If we have properties we need to load them, instantiate a PropertyDef and relate // it to its getter and setter. if (startPropertyList != -1) { MetadataRow[] table = _metadataStream.Tables[MetadataTables.Property]; MetadataRow[] methodSemantics = _metadataStream.Tables[MetadataTables.MethodSemantics]; // Now load all the methods between our index and the endOfMethodIndex for (int i = startPropertyList; i <= endPropertyList; i++) { PropertyMetadataTableRow propertyRow = table[i - 1] as PropertyMetadataTableRow; PropertyDef property = new PropertyDef( _references.Assembly, _references.Assembly.StringStream.GetString(propertyRow.NameIndex.Value), _builtType); // Get the related getter and setter methods for (int j = 0; j < methodSemantics.Length; j++) { MethodSemanticsMetadataTableRow semantics = methodSemantics[j] as MethodSemanticsMetadataTableRow; CodedIndex index = semantics.Association; if (index.Table == MetadataTables.Property && index.Index == i) { if (semantics.Semantics == MethodSemanticsAttributes.Setter) { property.Setter = _map.GetDefinition( MetadataTables.MethodDef, _metadataStream.GetEntryFor(MetadataTables.MethodDef, semantics.Method) ) as MethodDef; } else if (semantics.Semantics == MethodSemanticsAttributes.Getter) { property.Getter = _map.GetDefinition( MetadataTables.MethodDef, _metadataStream.GetEntryFor(MetadataTables.MethodDef, semantics.Method) ) as MethodDef; } } } _map.Add(MetadataTables.Property, propertyRow, property); _builtType.Properties.Add(property); } } }