Skip to content

Commit

Permalink
[Fix] Add missing selectros for NSExpression.
Browse files Browse the repository at this point in the history
Added the missing static factory methods and the missing property. In
order to give a clean API a new flag was added to the NSExpression class
to track if the Block property does return a block or a null ptr. The
idea is to avoid user from seeing an obj-c exception.

This commit fixes bug #35012:

https://bugzilla.xamarin.com/show_bug.cgi?id=35012

The evaluation of the NSExpression and the defition of the
NSExpressionHandler have also been fixed since both should be using
NSObjects.
  • Loading branch information
mandel-macaque committed May 16, 2016
1 parent ee07bcf commit f98e34b
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 7 deletions.
27 changes: 27 additions & 0 deletions src/Foundation/NSExpression.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;
using System.Runtime.InteropServices;

namespace XamCore.Foundation {

public partial class NSExpression {
bool hasFunction = false;

public static NSExpression FromFunction (NSExpressionHandler target, NSExpression[] parameters)
{
// NSExpression is a class cluster. The only subclass that supports the Block property is the one
// created by this static method. We set the flag so that the user does not get an obj-c exception
// when using the property and instead get a null ptr is returned.
var exp = _FromFunction (target, parameters);
exp.hasFunction = true;
return exp;
}

public NSExpressionHandler Block {
get {
if (hasFunction)
return this._Block;
return null;
}
}
}
}
19 changes: 12 additions & 7 deletions src/foundation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3152,8 +3152,7 @@ public interface NSException : NSCoding, NSCopying {
string[] CallStackSymbols { get; }
}

public delegate void NSExpressionHandler (NSObject evaluatedObject, NSExpression [] expressions, NSMutableDictionary context);

public delegate NSObject NSExpressionHandler (NSObject evaluatedObject, NSExpression [] expressions, NSMutableDictionary context);
[BaseType (typeof (NSObject))]
// Objective-C exception thrown. Name: NSInvalidArgumentException Reason: *** -predicateFormat cannot be sent to an abstract object of class NSExpression: Create a concrete instance!
[DisableDefaultCtor]
Expand All @@ -3173,9 +3172,12 @@ public interface NSExpression : NSSecureCoding, NSCopying {
[Static, Export ("expressionForFunction:arguments:")]
NSExpression FromFunction (string name, NSExpression[] parameters);

[Static, Export ("expressionWithFormat:")]
NSExpression FromFormat (string expressionFormat);

[Static, Export ("expressionWithFormat:argumentArray:")]
NSExpression FromFormat (string format, NSExpression [] parameters);
NSExpression FromFormat (string format, NSObject [] parameters);

//+ (NSExpression *)expressionForAggregate:(NSArray *)subexpressions;
[Static, Export ("expressionForAggregate:")]
NSExpression FromAggregate (NSExpression [] subexpressions);
Expand All @@ -3196,8 +3198,8 @@ public interface NSExpression : NSSecureCoding, NSCopying {
[Static, Export ("expressionForFunction:selectorName:arguments:")]
NSExpression FromFunction (NSExpression target, string name, NSExpression[] parameters);

[Static, Export ("expressionForBlock:arguments:")]
NSExpression FromFunction (NSExpressionHandler target, NSExpression[] parameters);
[Internal, Static, Export ("expressionForBlock:arguments:")]
NSExpression _FromFunction (NSExpressionHandler target, NSExpression[] parameters);

[Since (7,0), Mavericks]
[Static]
Expand Down Expand Up @@ -3258,8 +3260,11 @@ public interface NSExpression : NSSecureCoding, NSCopying {
[Export ("falseExpression")]
NSExpression FalseExpression { get; }

[Internal, Export ("expressionBlock")]
NSExpressionHandler _Block { get; }

[Export ("expressionValueWithObject:context:")]
NSExpression ExpressionValueWithObject (NSObject object1, NSMutableDictionary context);
NSObject ExpressionValueWithObject ([NullAllowed] NSObject object1, [NullAllowed] NSMutableDictionary context);
}

[iOS (8,0)][Mac (10,10, onlyOn64 : true)] // Not defined in 32-bit
Expand Down
1 change: 1 addition & 0 deletions src/frameworks.sources
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,7 @@ FOUNDATION_SOURCES = \
Foundation/NSDirectoryEnumerator.cs \
Foundation/NSDistributedNotificationCenter.cs \
Foundation/NSErrorException.cs \
Foundation/NSExpression.cs \
Foundation/NSExtension.cs \
Foundation/NSFastEnumerationState.cs \
Foundation/NSFastEnumerator.cs \
Expand Down

0 comments on commit f98e34b

Please sign in to comment.