Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 40 additions & 49 deletions src/Foundation/NSScriptCommandDescription.cs
Original file line number Diff line number Diff line change
@@ -1,34 +1,33 @@
// Copyright 2015 Xamarin, Inc.

// Disable until we get around to enable + fix any issues.
#nullable disable
#nullable enable

namespace Foundation {

#if MONOMAC || __MACCATALYST__

// The kyes are not found in any of the public headers from apple. That is the reason
// The keys are not found in any of the public headers from Apple. That is the reason
// to use this technique.
static class NSScriptCommonKeys {
private static NSString appEventCode = new NSString ("AppleEventCode");
static readonly NSString appEventCode = new NSString ("AppleEventCode");
public static NSString AppleEventCodeKey {
get { return appEventCode; }
}

private static NSString typeKey = new NSString ("Type");
static readonly NSString typeKey = new NSString ("Type");
public static NSString TypeKey {
get { return typeKey; }
}
}

public partial class NSScriptCommandDescription {

NSScriptCommandDescriptionDictionary description = null;
NSScriptCommandDescriptionDictionary? description;

static int ToIntValue (string fourCC)
{
if (fourCC.Length != 4)
throw new FormatException (string.Format ("{0} must have a lenght of 4", nameof (fourCC)));
throw new FormatException (string.Format ("{0} must have a length of 4", nameof (fourCC)));
int ret = 0;
for (int i = 0; i < 4; i++) {
ret <<= 8;
Expand All @@ -37,20 +36,20 @@ static int ToIntValue (string fourCC)
return ret;
}

/// <param name="suiteName">To be added.</param>
/// <param name="commandName">To be added.</param>
/// <param name="commandDeclaration">To be added.</param>
/// <summary>To be added.</summary>
/// <returns>To be added.</returns>
/// <remarks>To be added.</remarks>
/// <summary>Creates a new <see cref="NSScriptCommandDescription" /> with the specified suite name, command name, and command declaration.</summary>
/// <param name="suiteName">The name of the suite to which the command belongs.</param>
/// <param name="commandName">The name of the command.</param>
/// <param name="commandDeclaration">A dictionary containing the command declaration.</param>
/// <returns>A new <see cref="NSScriptCommandDescription" /> instance.</returns>
/// <exception cref="ArgumentException">Thrown when <paramref name="suiteName" /> or <paramref name="commandName" /> is null or empty, or when the command declaration is malformed.</exception>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="commandDeclaration" /> is <see langword="null" />.</exception>
public static NSScriptCommandDescription Create (string suiteName, string commandName, NSScriptCommandDescriptionDictionary commandDeclaration)
{
if (String.IsNullOrEmpty (suiteName))
throw new ArgumentException ("suiteName cannot be null or empty");
if (String.IsNullOrEmpty (commandName))
throw new ArgumentException ("commandName cannot be null or empty");
if (commandDeclaration is null)
throw new ArgumentNullException ("commandDeclaration");
ArgumentNullException.ThrowIfNull (commandDeclaration);

// ensure that the passed description is well formed
if (String.IsNullOrEmpty (commandDeclaration.CommandClass))
Expand Down Expand Up @@ -86,80 +85,72 @@ public static NSScriptCommandDescription Create (string suiteName, string comman
}
}

/// <summary>To be added.</summary>
/// <value>To be added.</value>
/// <remarks>To be added.</remarks>
/// <summary>Gets the Apple event class code for the command.</summary>
/// <value>A four-character string representing the Apple event class code.</value>
public string AppleEventClassCode {
get { return Runtime.ToFourCCString (FCCAppleEventClassCode); }
}

/// <summary>To be added.</summary>
/// <value>To be added.</value>
/// <remarks>To be added.</remarks>
/// <summary>Gets the Apple event code for the command.</summary>
/// <value>A four-character string representing the Apple event code.</value>
public string AppleEventCode {
get { return Runtime.ToFourCCString (FCCAppleEventCode); }
}

/// <param name="name">To be added.</param>
/// <summary>To be added.</summary>
/// <returns>To be added.</returns>
/// <remarks>To be added.</remarks>
public string GetTypeForArgument (string name)
/// <summary>Gets the type for the specified argument.</summary>
/// <param name="name">The name of the argument.</param>
/// <returns>The type of the argument, or <see langword="null" /> if the argument is not found.</returns>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="name" /> is <see langword="null" />.</exception>
public string? GetTypeForArgument (string name)
{
if (name is null)
throw new ArgumentNullException ("name");
ArgumentNullException.ThrowIfNull (name);

using (var nsName = new NSString (name))
using (var nsType = GetNSTypeForArgument (nsName)) {
return nsType?.ToString ();
}
}

/// <param name="name">To be added.</param>
/// <summary>To be added.</summary>
/// <returns>To be added.</returns>
/// <remarks>To be added.</remarks>
/// <summary>Gets the Apple event code for the specified argument.</summary>
/// <param name="name">The name of the argument.</param>
/// <returns>A four-character string representing the Apple event code for the argument.</returns>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="name" /> is <see langword="null" />.</exception>
public string GetAppleEventCodeForArgument (string name)
{
if (name is null)
throw new ArgumentNullException (name);
ArgumentNullException.ThrowIfNull (name);

using (var nsName = new NSString (name)) {
return Runtime.ToFourCCString (FCCAppleEventCodeForArgument (nsName));
}
}

/// <param name="name">To be added.</param>
/// <summary>To be added.</summary>
/// <returns>To be added.</returns>
/// <remarks>To be added.</remarks>
/// <summary>Determines whether the specified argument is optional.</summary>
/// <param name="name">The name of the argument.</param>
/// <returns><see langword="true" /> if the argument is optional; otherwise, <see langword="false" />.</returns>
public bool IsOptionalArgument (string name)
{
using (var nsName = new NSString (name)) {
return NSIsOptionalArgument (nsName);
}
}

/// <summary>To be added.</summary>
/// <value>To be added.</value>
/// <remarks>To be added.</remarks>
/// <summary>Gets the Apple event code for the return type.</summary>
/// <value>A four-character string representing the Apple event code for the return type.</value>
public string AppleEventCodeForReturnType {
get { return Runtime.ToFourCCString (FCCAppleEventCodeForReturnType); }
}

/// <summary>To be added.</summary>
/// <returns>To be added.</returns>
/// <remarks>To be added.</remarks>
/// <summary>Creates a new <see cref="NSScriptCommand" /> instance for this command description.</summary>
/// <returns>A new <see cref="NSScriptCommand" /> instance.</returns>
public NSScriptCommand CreateCommand ()
{
return new NSScriptCommand (CreateCommandInstancePtr ());
}

/// <summary>To be added.</summary>
/// <value>To be added.</value>
/// <remarks>To be added.</remarks>
public NSDictionary Dictionary {
get { return description.Dictionary; }
/// <summary>Gets the dictionary containing the command description.</summary>
/// <value>An <see cref="NSDictionary" /> containing the command description.</value>
public NSDictionary? Dictionary {
get { return description?.Dictionary; }
}
}
#endif
Expand Down
Loading