internal EventDefinition(MetadataReader reader, EventDefinitionHandle handle) { DebugCorlib.Assert(reader != null); DebugCorlib.Assert(!handle.IsNil); this.reader = reader; this.rowId = handle.RowId; }
internal abstract bool TryGetEventHandle(Cci.IEventDefinition def, out EventDefinitionHandle handle);
internal static uint ConvertEventHandleToTag(EventDefinitionHandle eventDef) { return (uint)eventDef.RowId << NumberOfBits | Event; }
public void AddEventMap(TypeDefinitionHandle declaringType, EventDefinitionHandle eventList) { _eventMapTable.Add(new EventMapRow { Parent = (uint)MetadataTokens.GetRowNumber(declaringType), EventList = (uint)MetadataTokens.GetRowNumber(eventList) }); }
// returns rowID internal int FindSemanticMethodsForEvent(EventDefinitionHandle eventDef, out ushort methodCount) { methodCount = 0; uint searchCodedTag = HasSemanticsTag.ConvertEventHandleToTag(eventDef); return this.BinarySearchTag(searchCodedTag, ref methodCount); }
internal EntityHandle GetEventType(EventDefinitionHandle handle) { int rowOffset = (handle.RowId - 1) * this.RowSize; return TypeDefOrRefTag.ConvertToHandle(this.Block.PeekTaggedReference(rowOffset + _EventTypeOffset, _IsTypeDefOrRefRefSizeSmall)); }
internal StringHandle GetName(EventDefinitionHandle handle) { int rowOffset = (handle.RowId - 1) * this.RowSize; return StringHandle.FromOffset(this.Block.PeekHeapReference(rowOffset + _NameOffset, _IsStringHeapRefSizeSmall)); }
public void IsNil() { Assert.False(ModuleDefinitionHandle.FromRowId(1).IsNil); Assert.False(AssemblyDefinitionHandle.FromRowId(1).IsNil); Assert.False(InterfaceImplementationHandle.FromRowId(1).IsNil); Assert.False(MethodDefinitionHandle.FromRowId(1).IsNil); Assert.False(MethodSpecificationHandle.FromRowId(1).IsNil); Assert.False(TypeDefinitionHandle.FromRowId(1).IsNil); Assert.False(ExportedTypeHandle.FromRowId(1).IsNil); Assert.False(TypeReferenceHandle.FromRowId(1).IsNil); Assert.False(TypeSpecificationHandle.FromRowId(1).IsNil); Assert.False(MemberReferenceHandle.FromRowId(1).IsNil); Assert.False(FieldDefinitionHandle.FromRowId(1).IsNil); Assert.False(EventDefinitionHandle.FromRowId(1).IsNil); Assert.False(PropertyDefinitionHandle.FromRowId(1).IsNil); Assert.False(StandaloneSignatureHandle.FromRowId(1).IsNil); Assert.False(MemberReferenceHandle.FromRowId(1).IsNil); Assert.False(FieldDefinitionHandle.FromRowId(1).IsNil); Assert.False(EventDefinitionHandle.FromRowId(1).IsNil); Assert.False(PropertyDefinitionHandle.FromRowId(1).IsNil); Assert.False(ParameterHandle.FromRowId(1).IsNil); Assert.False(GenericParameterHandle.FromRowId(1).IsNil); Assert.False(GenericParameterConstraintHandle.FromRowId(1).IsNil); Assert.False(ModuleReferenceHandle.FromRowId(1).IsNil); Assert.False(CustomAttributeHandle.FromRowId(1).IsNil); Assert.False(DeclarativeSecurityAttributeHandle.FromRowId(1).IsNil); Assert.False(ManifestResourceHandle.FromRowId(1).IsNil); Assert.False(ConstantHandle.FromRowId(1).IsNil); Assert.False(ManifestResourceHandle.FromRowId(1).IsNil); Assert.False(AssemblyFileHandle.FromRowId(1).IsNil); Assert.False(MethodImplementationHandle.FromRowId(1).IsNil); Assert.False(AssemblyReferenceHandle.FromRowId(1).IsNil); Assert.False(((EntityHandle)ModuleDefinitionHandle.FromRowId(1)).IsNil); Assert.False(((EntityHandle)AssemblyDefinitionHandle.FromRowId(1)).IsNil); Assert.False(((EntityHandle)InterfaceImplementationHandle.FromRowId(1)).IsNil); Assert.False(((EntityHandle)MethodDefinitionHandle.FromRowId(1)).IsNil); Assert.False(((EntityHandle)MethodSpecificationHandle.FromRowId(1)).IsNil); Assert.False(((EntityHandle)TypeDefinitionHandle.FromRowId(1)).IsNil); Assert.False(((EntityHandle)ExportedTypeHandle.FromRowId(1)).IsNil); Assert.False(((EntityHandle)TypeReferenceHandle.FromRowId(1)).IsNil); Assert.False(((EntityHandle)TypeSpecificationHandle.FromRowId(1)).IsNil); Assert.False(((EntityHandle)MemberReferenceHandle.FromRowId(1)).IsNil); Assert.False(((EntityHandle)FieldDefinitionHandle.FromRowId(1)).IsNil); Assert.False(((EntityHandle)EventDefinitionHandle.FromRowId(1)).IsNil); Assert.False(((EntityHandle)PropertyDefinitionHandle.FromRowId(1)).IsNil); Assert.False(((EntityHandle)StandaloneSignatureHandle.FromRowId(1)).IsNil); Assert.False(((EntityHandle)MemberReferenceHandle.FromRowId(1)).IsNil); Assert.False(((EntityHandle)FieldDefinitionHandle.FromRowId(1)).IsNil); Assert.False(((EntityHandle)EventDefinitionHandle.FromRowId(1)).IsNil); Assert.False(((EntityHandle)PropertyDefinitionHandle.FromRowId(1)).IsNil); Assert.False(((EntityHandle)ParameterHandle.FromRowId(1)).IsNil); Assert.False(((EntityHandle)GenericParameterHandle.FromRowId(1)).IsNil); Assert.False(((EntityHandle)GenericParameterConstraintHandle.FromRowId(1)).IsNil); Assert.False(((EntityHandle)ModuleReferenceHandle.FromRowId(1)).IsNil); Assert.False(((EntityHandle)CustomAttributeHandle.FromRowId(1)).IsNil); Assert.False(((EntityHandle)DeclarativeSecurityAttributeHandle.FromRowId(1)).IsNil); Assert.False(((EntityHandle)ManifestResourceHandle.FromRowId(1)).IsNil); Assert.False(((EntityHandle)ConstantHandle.FromRowId(1)).IsNil); Assert.False(((EntityHandle)ManifestResourceHandle.FromRowId(1)).IsNil); Assert.False(((EntityHandle)AssemblyFileHandle.FromRowId(1)).IsNil); Assert.False(((EntityHandle)MethodImplementationHandle.FromRowId(1)).IsNil); Assert.False(((EntityHandle)AssemblyReferenceHandle.FromRowId(1)).IsNil); Assert.False(StringHandle.FromOffset(1).IsNil); Assert.False(BlobHandle.FromOffset(1).IsNil); Assert.False(UserStringHandle.FromOffset(1).IsNil); Assert.False(GuidHandle.FromIndex(1).IsNil); Assert.False(DocumentNameBlobHandle.FromOffset(1).IsNil); Assert.False(((Handle)StringHandle.FromOffset(1)).IsNil); Assert.False(((Handle)BlobHandle.FromOffset(1)).IsNil); Assert.False(((Handle)UserStringHandle.FromOffset(1)).IsNil); Assert.False(((Handle)GuidHandle.FromIndex(1)).IsNil); Assert.False(((BlobHandle)DocumentNameBlobHandle.FromOffset(1)).IsNil); Assert.True(ModuleDefinitionHandle.FromRowId(0).IsNil); Assert.True(AssemblyDefinitionHandle.FromRowId(0).IsNil); Assert.True(InterfaceImplementationHandle.FromRowId(0).IsNil); Assert.True(MethodDefinitionHandle.FromRowId(0).IsNil); Assert.True(MethodSpecificationHandle.FromRowId(0).IsNil); Assert.True(TypeDefinitionHandle.FromRowId(0).IsNil); Assert.True(ExportedTypeHandle.FromRowId(0).IsNil); Assert.True(TypeReferenceHandle.FromRowId(0).IsNil); Assert.True(TypeSpecificationHandle.FromRowId(0).IsNil); Assert.True(MemberReferenceHandle.FromRowId(0).IsNil); Assert.True(FieldDefinitionHandle.FromRowId(0).IsNil); Assert.True(EventDefinitionHandle.FromRowId(0).IsNil); Assert.True(PropertyDefinitionHandle.FromRowId(0).IsNil); Assert.True(StandaloneSignatureHandle.FromRowId(0).IsNil); Assert.True(MemberReferenceHandle.FromRowId(0).IsNil); Assert.True(FieldDefinitionHandle.FromRowId(0).IsNil); Assert.True(EventDefinitionHandle.FromRowId(0).IsNil); Assert.True(PropertyDefinitionHandle.FromRowId(0).IsNil); Assert.True(ParameterHandle.FromRowId(0).IsNil); Assert.True(GenericParameterHandle.FromRowId(0).IsNil); Assert.True(GenericParameterConstraintHandle.FromRowId(0).IsNil); Assert.True(ModuleReferenceHandle.FromRowId(0).IsNil); Assert.True(CustomAttributeHandle.FromRowId(0).IsNil); Assert.True(DeclarativeSecurityAttributeHandle.FromRowId(0).IsNil); Assert.True(ManifestResourceHandle.FromRowId(0).IsNil); Assert.True(ConstantHandle.FromRowId(0).IsNil); Assert.True(ManifestResourceHandle.FromRowId(0).IsNil); Assert.True(AssemblyFileHandle.FromRowId(0).IsNil); Assert.True(MethodImplementationHandle.FromRowId(0).IsNil); Assert.True(AssemblyReferenceHandle.FromRowId(0).IsNil); Assert.True(((EntityHandle)ModuleDefinitionHandle.FromRowId(0)).IsNil); Assert.True(((EntityHandle)AssemblyDefinitionHandle.FromRowId(0)).IsNil); Assert.True(((EntityHandle)InterfaceImplementationHandle.FromRowId(0)).IsNil); Assert.True(((EntityHandle)MethodDefinitionHandle.FromRowId(0)).IsNil); Assert.True(((EntityHandle)MethodSpecificationHandle.FromRowId(0)).IsNil); Assert.True(((EntityHandle)TypeDefinitionHandle.FromRowId(0)).IsNil); Assert.True(((EntityHandle)ExportedTypeHandle.FromRowId(0)).IsNil); Assert.True(((EntityHandle)TypeReferenceHandle.FromRowId(0)).IsNil); Assert.True(((EntityHandle)TypeSpecificationHandle.FromRowId(0)).IsNil); Assert.True(((EntityHandle)MemberReferenceHandle.FromRowId(0)).IsNil); Assert.True(((EntityHandle)FieldDefinitionHandle.FromRowId(0)).IsNil); Assert.True(((EntityHandle)EventDefinitionHandle.FromRowId(0)).IsNil); Assert.True(((EntityHandle)PropertyDefinitionHandle.FromRowId(0)).IsNil); Assert.True(((EntityHandle)StandaloneSignatureHandle.FromRowId(0)).IsNil); Assert.True(((EntityHandle)MemberReferenceHandle.FromRowId(0)).IsNil); Assert.True(((EntityHandle)FieldDefinitionHandle.FromRowId(0)).IsNil); Assert.True(((EntityHandle)EventDefinitionHandle.FromRowId(0)).IsNil); Assert.True(((EntityHandle)PropertyDefinitionHandle.FromRowId(0)).IsNil); Assert.True(((EntityHandle)ParameterHandle.FromRowId(0)).IsNil); Assert.True(((EntityHandle)GenericParameterHandle.FromRowId(0)).IsNil); Assert.True(((EntityHandle)GenericParameterConstraintHandle.FromRowId(0)).IsNil); Assert.True(((EntityHandle)ModuleReferenceHandle.FromRowId(0)).IsNil); Assert.True(((EntityHandle)CustomAttributeHandle.FromRowId(0)).IsNil); Assert.True(((EntityHandle)DeclarativeSecurityAttributeHandle.FromRowId(0)).IsNil); Assert.True(((EntityHandle)ManifestResourceHandle.FromRowId(0)).IsNil); Assert.True(((EntityHandle)ConstantHandle.FromRowId(0)).IsNil); Assert.True(((EntityHandle)ManifestResourceHandle.FromRowId(0)).IsNil); Assert.True(((EntityHandle)AssemblyFileHandle.FromRowId(0)).IsNil); Assert.True(((EntityHandle)MethodImplementationHandle.FromRowId(0)).IsNil); Assert.True(((EntityHandle)AssemblyReferenceHandle.FromRowId(0)).IsNil); // heaps: Assert.True(StringHandle.FromOffset(0).IsNil); Assert.True(BlobHandle.FromOffset(0).IsNil); Assert.True(UserStringHandle.FromOffset(0).IsNil); Assert.True(GuidHandle.FromIndex(0).IsNil); Assert.True(DocumentNameBlobHandle.FromOffset(0).IsNil); Assert.True(((Handle)StringHandle.FromOffset(0)).IsNil); Assert.True(((Handle)BlobHandle.FromOffset(0)).IsNil); Assert.True(((Handle)UserStringHandle.FromOffset(0)).IsNil); Assert.True(((Handle)GuidHandle.FromIndex(0)).IsNil); Assert.True(((BlobHandle)DocumentNameBlobHandle.FromOffset(0)).IsNil); // virtual: Assert.False(AssemblyReferenceHandle.FromVirtualIndex(0).IsNil); Assert.False(StringHandle.FromVirtualIndex(0).IsNil); Assert.False(BlobHandle.FromVirtualIndex(0, 0).IsNil); Assert.False(((Handle)AssemblyReferenceHandle.FromVirtualIndex(0)).IsNil); Assert.False(((Handle)StringHandle.FromVirtualIndex(0)).IsNil); Assert.False(((Handle)BlobHandle.FromVirtualIndex(0, 0)).IsNil); }
public Mapping<EventDefinitionHandle> MapEventDefinition(EventDefinitionHandle handle) { return _eventDefinitions.GetOrAdd(handle, MapEventDefinitionImpl); }
private Mapping<EventDefinitionHandle> MapEventDefinitionImpl(EventDefinitionHandle handle) { EventDefinition eventDefinition = _sourceMetadata.GetEventDefinition(handle); EventAccessors accessors = eventDefinition.GetAccessors(); // events always have an adder method, so use that to find the declaring type MethodDefinition adderMethodDefinition = _sourceMetadata.GetMethodDefinition(accessors.Adder); Mapping<TypeDefinitionHandle> declaringTypeMapping = MapTypeDefinition(adderMethodDefinition.GetDeclaringType()); if (declaringTypeMapping.Target.IsNil) return new Mapping<EventDefinitionHandle>(); // Make sure each of the accessors maps successfully. Only the raiser is optional. Mapping<MethodDefinitionHandle> adderMethodDefinitionMapping = MapMethodDefinition(accessors.Adder); if (adderMethodDefinitionMapping.Target.IsNil) return new Mapping<EventDefinitionHandle>(); Mapping<MethodDefinitionHandle> removerMethodDefinitionMapping = MapMethodDefinition(accessors.Remover); if (removerMethodDefinitionMapping.Target.IsNil) return new Mapping<EventDefinitionHandle>(); Mapping<MethodDefinitionHandle> raiserMethodDefinitionMapping = default(Mapping<MethodDefinitionHandle>); if (!accessors.Raiser.IsNil) { raiserMethodDefinitionMapping = MapMethodDefinition(accessors.Raiser); if (raiserMethodDefinitionMapping.Target.IsNil) return new Mapping<EventDefinitionHandle>(); } // locate the target event by name string eventName = _sourceMetadata.GetString(eventDefinition.Name); EventDefinitionHandle targetEventDefinitionHandle = default(EventDefinitionHandle); EventDefinition targetEventDefinition = default(EventDefinition); foreach (var targetHandle in _targetMetadata.EventDefinitions) { targetEventDefinition = _targetMetadata.GetEventDefinition(targetHandle); MethodDefinition targetAdderMethodDefinition = _targetMetadata.GetMethodDefinition(targetEventDefinition.GetAccessors().Adder); if (targetAdderMethodDefinition.GetDeclaringType() != declaringTypeMapping.Target) continue; if (!_targetMetadata.StringComparer.Equals(targetEventDefinition.Name, eventName)) continue; targetEventDefinitionHandle = targetHandle; break; } if (targetEventDefinitionHandle.IsNil) return new Mapping<EventDefinitionHandle>(); EventAccessors targetAccessors = targetEventDefinition.GetAccessors(); if (targetAccessors.Adder != adderMethodDefinitionMapping.Target) return new Mapping<EventDefinitionHandle>(); if (targetAccessors.Remover != removerMethodDefinitionMapping.Target) return new Mapping<EventDefinitionHandle>(); if (!accessors.Raiser.IsNil) { if (targetAccessors.Raiser != raiserMethodDefinitionMapping.Target) return new Mapping<EventDefinitionHandle>(); } return new Mapping<EventDefinitionHandle>(targetEventDefinitionHandle); }
internal Handle GetEventType(EventDefinitionHandle handle) { int rowOffset = (int)(handle.RowId - 1) * this.RowSize; return TypeDefOrRefTag.ConvertToToken(this.Block.PeekTaggedReference(rowOffset + this.EventTypeOffset, this.IsTypeDefOrRefRefSizeSmall)); }
internal StringHandle GetName(EventDefinitionHandle handle) { int rowOffset = (int)(handle.RowId - 1) * this.RowSize; return StringHandle.FromIndex(this.Block.PeekReference(rowOffset + this.NameOffset, this.IsStringHeapRefSizeSmall)); }
public EventDefinition GetEventDefinition(EventDefinitionHandle handle) { return new EventDefinition(this, handle); }
internal EventAttributes GetFlags(EventDefinitionHandle handle) { int rowOffset = (handle.RowId - 1) * this.RowSize; return (EventAttributes)this.Block.PeekUInt16(rowOffset + _FlagsOffset); }
internal PEEventSymbol( PEModuleSymbol moduleSymbol, PENamedTypeSymbol containingType, EventDefinitionHandle handle, PEMethodSymbol addMethod, PEMethodSymbol removeMethod, MultiDictionary<string, PEFieldSymbol> privateFieldNameToSymbols) { Debug.Assert((object)moduleSymbol != null); Debug.Assert((object)containingType != null); Debug.Assert(!handle.IsNil); Debug.Assert((object)addMethod != null); Debug.Assert((object)removeMethod != null); _addMethod = addMethod; _removeMethod = removeMethod; _handle = handle; _containingType = containingType; EventAttributes mdFlags = 0; EntityHandle eventType = default(EntityHandle); try { var module = moduleSymbol.Module; module.GetEventDefPropsOrThrow(handle, out _name, out mdFlags, out eventType); } catch (BadImageFormatException mrEx) { if ((object)_name == null) { _name = string.Empty; } _lazyUseSiteDiagnostic = new CSDiagnosticInfo(ErrorCode.ERR_BindToBogus, this); if (eventType.IsNil) { _eventType = new UnsupportedMetadataTypeSymbol(mrEx); } } TypeSymbol originalEventType = _eventType; if ((object)_eventType == null) { var metadataDecoder = new MetadataDecoder(moduleSymbol, containingType); originalEventType = metadataDecoder.GetTypeOfToken(eventType); const int targetSymbolCustomModifierCount = 0; _eventType = DynamicTypeDecoder.TransformType(originalEventType, targetSymbolCustomModifierCount, handle, moduleSymbol); _eventType = TupleTypeDecoder.DecodeTupleTypesIfApplicable(_eventType, handle, moduleSymbol); } // IsWindowsRuntimeEvent checks the signatures, so we just have to check the accessors. bool isWindowsRuntimeEvent = IsWindowsRuntimeEvent; bool callMethodsDirectly = isWindowsRuntimeEvent ? !DoModifiersMatch(_addMethod, _removeMethod) : !DoSignaturesMatch(moduleSymbol, originalEventType, _addMethod, _removeMethod); if (callMethodsDirectly) { _flags |= Flags.CallMethodsDirectly; } else { _addMethod.SetAssociatedEvent(this, MethodKind.EventAdd); _removeMethod.SetAssociatedEvent(this, MethodKind.EventRemove); PEFieldSymbol associatedField = GetAssociatedField(privateFieldNameToSymbols, isWindowsRuntimeEvent); if ((object)associatedField != null) { _associatedFieldOpt = associatedField; associatedField.SetAssociatedEvent(this); } } if ((mdFlags & EventAttributes.SpecialName) != 0) { _flags |= Flags.IsSpecialName; } if ((mdFlags & EventAttributes.RTSpecialName) != 0) { _flags |= Flags.IsRuntimeSpecialName; } }
public static string ToString(this MetadataReader reader, EventDefinitionHandle x) => reader.ToString(reader.GetEventDefinition(x));