From 88781ddafd0cf4264b25c4ac5d6c04f0748e1229 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Mon, 23 Jul 2018 22:36:57 +0200 Subject: [PATCH] Add IAttribute.GetAttribute/IAttribute.HasAttribute extensions --- .../TypeSystem/TypeSystemExtensions.cs | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/ICSharpCode.Decompiler/TypeSystem/TypeSystemExtensions.cs b/ICSharpCode.Decompiler/TypeSystem/TypeSystemExtensions.cs index b14cc73a1..ba6e4fe47 100644 --- a/ICSharpCode.Decompiler/TypeSystem/TypeSystemExtensions.cs +++ b/ICSharpCode.Decompiler/TypeSystem/TypeSystemExtensions.cs @@ -439,6 +439,31 @@ namespace ICSharpCode.Decompiler.TypeSystem } #endregion + #region IParameter.GetAttribute + /// + /// Gets whether the parameter has an attribute of the specified attribute type (or derived attribute types). + /// + /// The parameter on which the attributes are declared. + /// The attribute type to look for. + public static bool HasAttribute(this IParameter parameter, KnownAttribute attrType) + { + return GetAttribute(parameter, attrType) != null; + } + + /// + /// Gets the attribute of the specified attribute type (or derived attribute types). + /// + /// The parameter on which the attributes are declared. + /// The attribute type to look for. + /// + /// Returns the attribute that was found; or null if none was found. + /// + public static IAttribute GetAttribute(this IParameter parameter, KnownAttribute attributeType) + { + return parameter.GetAttributes().FirstOrDefault(a => a.AttributeType.IsKnownType(attributeType)); + } + #endregion + #region IAssembly.GetTypeDefinition(string,string,int) /// /// Gets the type definition for a top-level type.