Skip to content

Commit

Permalink
Added MarshalingBehaviorAttribute support
Browse files Browse the repository at this point in the history
  • Loading branch information
tristanlabelle committed Nov 17, 2023
1 parent 46dd306 commit 6c89ec1
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 8 deletions.
28 changes: 28 additions & 0 deletions Sources/WindowsMetadata/MarshalingBehaviorAttribute.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import DotNetMetadata

/// Indicates the threading model of a Windows Runtime component.
public enum MarshalingBehaviorAttribute: AttributeType {
public static var namespace: String? { "Windows.Foundation.Metadata" }
public static var name: String { "MarshalingBehaviorAttribute" }
public static var validOn: AttributeTargets { .class }
public static var allowMultiple: Bool { false }
public static var inherited: Bool { true }

public static func decode(_ attribute: Attribute) throws -> MarshalingType {
let arguments = try attribute.arguments
guard arguments.count == 1,
case .constant(let constant) = arguments[0],
case .int32(let value) = constant,
let marshalingType = MarshalingType(rawValue: value) else { throw InvalidMetadataError.attributeArguments }
return marshalingType
}
}

public enum MarshalingType: Int32, Hashable {
/// The class prevents marshaling on all interfaces.
case none = 1
/// The class marshals and unmarshals to the same pointer value on all interfaces.
case agile = 2
/// The class does not implement IMarshal or forwards to CoGetStandardMarshal on all interfaces.
case standard = 3
}
9 changes: 9 additions & 0 deletions Sources/WindowsMetadata/ThreadingAttribute.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,13 @@ public enum ThreadingAttribute: AttributeType {
let threadingModel = ThreadingModel(rawValue: value) else { throw InvalidMetadataError.attributeArguments }
return threadingModel
}
}

public enum ThreadingModel: Int32, Hashable {
/// Single-threaded apartment
case sta = 1
/// Multithreaded apartment
case mta = 2
/// Both single-threaded and multithreaded apartments
case both = 3
}
8 changes: 0 additions & 8 deletions Sources/WindowsMetadata/ThreadingModel.swift

This file was deleted.

0 comments on commit 6c89ec1

Please sign in to comment.