/* 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; using System.Collections.Generic; using System.Collections.ObjectModel; namespace dnSpy.Debugger.DotNet.Metadata { /// /// .NET method signature /// public sealed class DmdMethodSignature : IEquatable { /// /// Gets the flags /// public DmdSignatureCallingConvention Flags { get; } /// /// true if it's a generic method signature /// public bool IsGeneric => (Flags & DmdSignatureCallingConvention.Generic) != 0; /// /// true if 'this' is a hidden parameter /// public bool HasThis => (Flags & DmdSignatureCallingConvention.HasThis) != 0; /// /// true if 'this' is an explicit parameter /// public bool ExplicitThis => (Flags & DmdSignatureCallingConvention.ExplicitThis) != 0; /// /// Generic parameter count /// public int GenericParameterCount { get; } /// /// Gets the return type /// public DmdType ReturnType { get; } internal bool HasTypeEquivalence { get { if (ReturnType.HasTypeEquivalence) return true; var list = parameterTypes; for (int i = 0; i < list.Count; i++) { if (list[i].HasTypeEquivalence) return true; } list = varArgsParameterTypes; for (int i = 0; i < list.Count; i++) { if (list[i].HasTypeEquivalence) return true; } return false; } } readonly ReadOnlyCollection parameterTypes; readonly ReadOnlyCollection varArgsParameterTypes; /// /// Constructor /// /// Flags /// Number of generic parameters /// Return type /// Parameter types or null /// Var args parameter types or null public DmdMethodSignature(DmdSignatureCallingConvention flags, int genericParameterCount, DmdType returnType, IList? parameterTypes, IList? varArgsParameterTypes) { if (genericParameterCount < 0) throw new ArgumentOutOfRangeException(nameof(genericParameterCount)); Flags = flags; GenericParameterCount = genericParameterCount; ReturnType = returnType ?? throw new ArgumentNullException(nameof(returnType)); this.parameterTypes = ReadOnlyCollectionHelpers.Create(parameterTypes); this.varArgsParameterTypes = ReadOnlyCollectionHelpers.Create(varArgsParameterTypes); } /// /// Gets the parameter types, see also /// /// public ReadOnlyCollection GetParameterTypes() => parameterTypes; /// /// Gets the var args parameter types /// /// public ReadOnlyCollection GetVarArgsParameterTypes() => varArgsParameterTypes; #pragma warning disable CS1591 // Missing XML comment for publicly visible type or member public static bool operator ==(DmdMethodSignature? left, DmdMethodSignature? right) => DmdMemberInfoEqualityComparer.DefaultMember.Equals(left, right); public static bool operator !=(DmdMethodSignature? left, DmdMethodSignature? right) => !DmdMemberInfoEqualityComparer.DefaultMember.Equals(left, right); #pragma warning restore CS1591 // Missing XML comment for publicly visible type or member /// /// Equals() /// /// /// public bool Equals(DmdMethodSignature? other) => DmdMemberInfoEqualityComparer.DefaultMember.Equals(this, other); /// /// Equals() /// /// /// public override bool Equals(object? obj) => Equals(obj as DmdMethodSignature); /// /// GetHashCode() /// /// public override int GetHashCode() => DmdMemberInfoEqualityComparer.DefaultMember.GetHashCode(this); /// /// ToString() /// /// public sealed override string ToString() => DmdMemberFormatter.Format(this); } }