From fedf343aabbb582d6c264494627b3a581c23193b Mon Sep 17 00:00:00 2001 From: Tristan Labelle Date: Tue, 17 Oct 2023 06:14:25 -0400 Subject: [PATCH] Added a getter for System's GuidAttribute --- Sources/DotNetMetadata/SystemAttributes.swift | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Sources/DotNetMetadata/SystemAttributes.swift b/Sources/DotNetMetadata/SystemAttributes.swift index bbeca7c..3a81405 100644 --- a/Sources/DotNetMetadata/SystemAttributes.swift +++ b/Sources/DotNetMetadata/SystemAttributes.swift @@ -44,10 +44,20 @@ public enum SystemAttributes { let arguments = try attribute.arguments guard arguments.count == 1, case .constant(let constant) = arguments[0], - case .boolean(let value) = constant else { - throw InvalidMetadataError.attributeArguments + case .boolean(let value) = constant else { throw InvalidMetadataError.attributeArguments } + + return value + } + + public static func getGuid(_ type: TypeDefinition) throws -> String? { + guard let attribute = try type.firstAttribute(namespace: "System.Runtime.InteropServices", name: "GuidAttribute") else { + return nil } + let arguments = try attribute.arguments + guard arguments.count == 1, + case .constant(let constant) = arguments[0], + case .string(let value) = constant else { throw InvalidMetadataError.attributeArguments } return value } } \ No newline at end of file