/* 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.ObjectModel; using dnSpy.Debugger.DotNet.Metadata.Impl; namespace dnSpy.Debugger.DotNet.Metadata { /// /// A .NET method parameter /// public abstract class DmdParameterInfo : DmdObject, IDmdCustomAttributeProvider, IEquatable { /// /// Dummy abstract method to make sure no-one outside this assembly can create their own /// private protected abstract void YouCantDeriveFromThisClass(); /// /// Gets the parameter type /// public abstract DmdType ParameterType { get; } /// /// Gets the parameter name /// public abstract string? Name { get; } /// /// true if is valid /// public abstract bool HasDefaultValue { get; } /// /// Gets the default value, see also /// public abstract object? RawDefaultValue { get; } /// /// Gets the parameter index /// public abstract int Position { get; } /// /// Gets the parameter attributes /// public abstract DmdParameterAttributes Attributes { get; } #pragma warning disable CS1591 // Missing XML comment for publicly visible type or member public bool IsIn => (Attributes & DmdParameterAttributes.In) != 0; public bool IsOut => (Attributes & DmdParameterAttributes.Out) != 0; public bool IsLcid => (Attributes & DmdParameterAttributes.Lcid) != 0; public bool IsRetval => (Attributes & DmdParameterAttributes.Retval) != 0; public bool IsOptional => (Attributes & DmdParameterAttributes.Optional) != 0; public bool HasDefault => (Attributes & DmdParameterAttributes.HasDefault) != 0; public bool HasFieldMarshal => (Attributes & DmdParameterAttributes.HasFieldMarshal) != 0; #pragma warning restore CS1591 // Missing XML comment for publicly visible type or member /// /// Gets the owner method or property /// public abstract DmdMemberInfo Member { get; } /// /// true if this is not the real method parameter since the declaring method is just a reference. /// Resolve the method to get the real method parameters. /// public bool IsMetadataReference => Member.IsMetadataReference; /// /// Gets the metadata token /// public abstract int MetadataToken { get; } /// /// Gets all required custom modifiers /// /// public DmdType[] GetRequiredCustomModifiers() => DmdCustomModifierUtilities.GetModifiers(GetCustomModifiers(), requiredModifiers: true); /// /// Gets all optional custom modifiers /// /// public DmdType[] GetOptionalCustomModifiers() => DmdCustomModifierUtilities.GetModifiers(GetCustomModifiers(), requiredModifiers: false); /// /// Gets all custom modifiers /// /// public ReadOnlyCollection GetCustomModifiers() => ParameterType.GetCustomModifiers(); /// /// Gets the custom attributes /// public ReadOnlyCollection CustomAttributes => GetCustomAttributesData(); /// /// Gets the custom attributes /// /// public abstract ReadOnlyCollection GetCustomAttributesData(); /// /// Checks if a custom attribute is present /// /// Full name of the custom attribute type /// true to check custom attributes in all base classes /// public bool IsDefined(string attributeTypeFullName, bool inherit) => CustomAttributesHelper.IsDefined(GetCustomAttributesData(), attributeTypeFullName); /// /// Checks if a custom attribute is present /// /// Custom attribute type /// true to check custom attributes in all base classes /// public bool IsDefined(DmdType? attributeType, bool inherit) => CustomAttributesHelper.IsDefined(GetCustomAttributesData(), attributeType); /// /// Checks if a custom attribute is present /// /// Custom attribute type /// true to check custom attributes in all base classes /// public bool IsDefined(Type attributeType, bool inherit) => CustomAttributesHelper.IsDefined(GetCustomAttributesData(), DmdTypeUtilities.ToDmdType(attributeType, Member.AppDomain)); /// /// Finds a custom attribute /// /// Full name of the custom attribute type /// true to check custom attributes in all base classes /// public DmdCustomAttributeData? FindCustomAttribute(string attributeTypeFullName, bool inherit) => CustomAttributesHelper.Find(GetCustomAttributesData(), attributeTypeFullName); /// /// Finds a custom attribute /// /// Custom attribute type /// true to check custom attributes in all base classes /// public DmdCustomAttributeData? FindCustomAttribute(DmdType? attributeType, bool inherit) => CustomAttributesHelper.Find(GetCustomAttributesData(), attributeType); /// /// Finds a custom attribute /// /// Custom attribute type /// true to check custom attributes in all base classes /// public DmdCustomAttributeData? FindCustomAttribute(Type attributeType, bool inherit) => CustomAttributesHelper.Find(GetCustomAttributesData(), DmdTypeUtilities.ToDmdType(attributeType, Member.AppDomain)); #pragma warning disable CS1591 // Missing XML comment for publicly visible type or member public static bool operator ==(DmdParameterInfo? left, DmdParameterInfo? right) => DmdMemberInfoEqualityComparer.DefaultParameter.Equals(left, right); public static bool operator !=(DmdParameterInfo? left, DmdParameterInfo? right) => !DmdMemberInfoEqualityComparer.DefaultParameter.Equals(left, right); #pragma warning restore CS1591 // Missing XML comment for publicly visible type or member /// /// Equals() /// /// /// public bool Equals(DmdParameterInfo? other) => DmdMemberInfoEqualityComparer.DefaultParameter.Equals(this, other); /// /// Equals() /// /// /// public override bool Equals(object? obj) => Equals(obj as DmdParameterInfo); /// /// GetHashCode() /// /// public override int GetHashCode() => DmdMemberInfoEqualityComparer.DefaultParameter.GetHashCode(this); /// /// ToString() /// /// public sealed override string ToString() => DmdMemberFormatter.Format(this); } }