Skip to content

Commit

Permalink
Added a getter for System's GuidAttribute
Browse files Browse the repository at this point in the history
  • Loading branch information
tristanlabelle committed Oct 17, 2023
1 parent f83920e commit fedf343
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions Sources/DotNetMetadata/SystemAttributes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

0 comments on commit fedf343

Please sign in to comment.