public EventMetadataICodeElementAdapter(Event @event, TypeDefinition typeDefinition, IList<TypeDescriptor> genericTypes, MetadataReader reader) : base(typeDefinition, genericTypes, reader) { if (@event == null) { throw new ArgumentNullException("event"); } this.Event = @event; }
public Event GetEventProperties(int token) { // The Event's name will be stored in this array. The 1024 is a "magical number", seems like a type's name can be maximum this long. The corhlpr.h also defines a suspicious constant like this: #define MAX_CLASSNAME_LENGTH 1024 var eventName = new char[1024]; var typeDefToken = 0; // Number of how many characters were filled in the typeName array. var nameLength = 0; // Event's flags. var eventFlags = 0; // A pointer to a TypeRef or TypeDef metadata token representing the Delegate type of the event. var eventTypeToken = 0; // method token AddOn var methodTokenAddOn = 0; // method token RemoveOn var methodTokenRemoveOn = 0; // method token Fire var methodTokenFire = 0; var otherMethodTokens = new int[1024]; var otherMethodTokensCount = 0; // Get the Event's properties. var hresult = this.import.GetEventProps( token, ref typeDefToken, eventName, eventName.Length, ref nameLength, ref eventFlags, ref eventTypeToken, ref methodTokenAddOn, ref methodTokenRemoveOn, ref methodTokenFire, otherMethodTokens, 1024, ref otherMethodTokensCount); if (hresult != 0) { Marshal.ThrowExceptionForHR(hresult); } // supress names "" & "\0"; if (nameLength <= 1) { // return null for this, we do not need to know about empty base return null; } // Get the Event's name. var fullTypeName = new string(eventName, 0, nameLength - 1); var otherMethods = new Method[otherMethodTokensCount]; for (var otherMethodTokenIndex = 0; otherMethodTokenIndex < otherMethodTokensCount; otherMethodTokenIndex++) { otherMethods[otherMethodTokenIndex] = this.GetMethodProperties(otherMethodTokens[otherMethodTokenIndex]); } var eventProperties = new Event { Token = token, FullName = fullTypeName, Flags = (CorEventAttr)eventFlags, Type = eventTypeToken.Is(CorTokenType.TypeDef) ? (object)this.GetTypeDefinitionProperties(eventTypeToken) : (object)this.GetTypeReferenceProperties(eventTypeToken), AddOn = this.GetMethodProperties(methodTokenAddOn), RemoveOn = this.GetMethodProperties(methodTokenRemoveOn), Fire = methodTokenFire.IsNotEmpty(CorTokenType.MethodDef) ? this.GetMethodProperties(methodTokenFire) : null, Other = otherMethods }; return eventProperties; }