/* Copyright (C) 2014-2019 de4dot@gmail.com This file is part of dnSpy dnSpy is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. dnSpy is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with dnSpy. If not, see . */ using System; namespace dnSpy.Debugger.DotNet.Metadata { /// /// A .NET event /// public abstract class DmdEventInfo : DmdMemberInfo, IEquatable { /// /// Gets the AppDomain /// public sealed override DmdAppDomain AppDomain => DeclaringType!.AppDomain; /// /// Gets the member type /// public sealed override DmdMemberTypes MemberType => DmdMemberTypes.Event; /// /// Gets the event attributes /// public abstract DmdEventAttributes Attributes { get; } #pragma warning disable CS1591 // Missing XML comment for publicly visible type or member public bool IsSpecialName => (Attributes & DmdEventAttributes.SpecialName) != 0; public bool IsRTSpecialName => (Attributes & DmdEventAttributes.RTSpecialName) != 0; #pragma warning restore CS1591 // Missing XML comment for publicly visible type or member /// /// Gets the event handler type /// public abstract DmdType EventHandlerType { get; } /// /// true if it's a multi-cast delegate /// public bool IsMulticast { get { var multicastDelegate = DeclaringType!.Assembly.AppDomain.System_MulticastDelegate; return multicastDelegate.IsAssignableFrom(EventHandlerType); } } /// /// Resolves a member reference /// /// true to throw if it doesn't exist, false to return null if it doesn't exist /// public sealed override DmdMemberInfo? ResolveMember(bool throwOnError) => this; /// /// Returns false since there are no event references /// public sealed override bool IsMetadataReference => false; /// /// Gets the add method /// public DmdMethodInfo? AddMethod => GetAddMethod(nonPublic: true); /// /// Gets the remove method /// public DmdMethodInfo? RemoveMethod => GetRemoveMethod(nonPublic: true); /// /// Gets the raise method /// public DmdMethodInfo? RaiseMethod => GetRaiseMethod(nonPublic: true); /// /// Gets all public 'other' methods /// /// public DmdMethodInfo[] GetOtherMethods() => GetOtherMethods(nonPublic: false); /// /// Gets the public add method /// /// public DmdMethodInfo? GetAddMethod() => GetAddMethod(nonPublic: false); /// /// Gets the public remove method /// /// public DmdMethodInfo? GetRemoveMethod() => GetRemoveMethod(nonPublic: false); /// /// Gets the public raise method /// /// public DmdMethodInfo? GetRaiseMethod() => GetRaiseMethod(nonPublic: false); /// /// Gets 'other' methods /// /// true to include all methods, false to only include public methods /// public DmdMethodInfo[] GetOtherMethods(bool nonPublic) => GetOtherMethods(nonPublic ? DmdGetAccessorOptions.NonPublic : DmdGetAccessorOptions.None); /// /// Gets 'other' methods /// /// Options /// public abstract DmdMethodInfo[] GetOtherMethods(DmdGetAccessorOptions options); /// /// Gets the add method /// /// true to return any method, false to only return a public method /// public DmdMethodInfo? GetAddMethod(bool nonPublic) => GetAddMethod(nonPublic ? DmdGetAccessorOptions.NonPublic : DmdGetAccessorOptions.None); /// /// Gets the add method /// /// Options /// public abstract DmdMethodInfo? GetAddMethod(DmdGetAccessorOptions options); /// /// Gets the remove method /// /// true to return any method, false to only return a public method /// public DmdMethodInfo? GetRemoveMethod(bool nonPublic) => GetRemoveMethod(nonPublic ? DmdGetAccessorOptions.NonPublic : DmdGetAccessorOptions.None); /// /// Gets the remove method /// /// Options /// public abstract DmdMethodInfo? GetRemoveMethod(DmdGetAccessorOptions options); /// /// Gets the raise method /// /// true to return any method, false to only return a public method /// public DmdMethodInfo? GetRaiseMethod(bool nonPublic) => GetRaiseMethod(nonPublic ? DmdGetAccessorOptions.NonPublic : DmdGetAccessorOptions.None); /// /// Gets the raise method /// /// Options /// public abstract DmdMethodInfo? GetRaiseMethod(DmdGetAccessorOptions options); #pragma warning disable CS1591 // Missing XML comment for publicly visible type or member public static bool operator ==(DmdEventInfo? left, DmdEventInfo? right) => DmdMemberInfoEqualityComparer.DefaultMember.Equals(left, right); public static bool operator !=(DmdEventInfo? left, DmdEventInfo? right) => !DmdMemberInfoEqualityComparer.DefaultMember.Equals(left, right); #pragma warning restore CS1591 // Missing XML comment for publicly visible type or member /// /// Equals() /// /// /// public bool Equals(DmdEventInfo? other) => DmdMemberInfoEqualityComparer.DefaultMember.Equals(this, other); /// /// Equals() /// /// /// public override bool Equals(object? obj) => Equals(obj as DmdEventInfo); /// /// GetHashCode() /// /// public override int GetHashCode() => DmdMemberInfoEqualityComparer.DefaultMember.GetHashCode(this); /// /// ToString() /// /// public sealed override string? ToString() => DmdMemberFormatter.Format(this); } }