-
Notifications
You must be signed in to change notification settings - Fork 515
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Fix] Add missing selectors for NSExpression.
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
1 parent
323c7f4
commit 5508aa3
Showing
3 changed files
with
225 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
// TODO: The NSExpression class is a cluster class in cococa. This means that now all the properties are supported by all the types of NSExpressions. | ||
// At the point of this written all the properties have been tested with all types EXCEPT NSExpressionType.Subquery and NSExpressionType.Conditional because writting | ||
// tests for those was not possible. The properties for these two types have been deduced from the other types yet bugs are possible and an objc excection will be thrown. | ||
using System; | ||
using System.Runtime.InteropServices; | ||
using XamCore.ObjCRuntime; | ||
|
||
namespace XamCore.Foundation { | ||
|
||
public partial class NSExpression { | ||
|
||
[Export ("arguments")] | ||
public virtual NSExpression[] Arguments { | ||
get { | ||
var type = ExpressionType; | ||
if (type != NSExpressionType.Function && type != NSExpressionType.Block && type != NSExpressionType.KeyPath) | ||
throw new InvalidOperationException ( | ||
$"NSExpressions of type {type} do not support the Arguments property. Expressions that support the property " | ||
+ "are of type Function, Block and KeyPath"); | ||
return _Arguments; | ||
} | ||
} | ||
|
||
|
||
[Export ("collection")] | ||
public virtual NSObject Collection { | ||
get { | ||
var type = ExpressionType; | ||
if (type != NSExpressionType.NSAggregate) | ||
throw new InvalidOperationException ( | ||
$"NSExpressions of type {type} do not support the Collection property. Expressions that support the property " | ||
+ "are of type NSAggregate"); | ||
return _Collection; | ||
} | ||
} | ||
|
||
[Export ("predicate")] | ||
public virtual NSPredicate Predicate { | ||
get { | ||
var type = ExpressionType; | ||
if (type != NSExpressionType.Conditional && type != NSExpressionType.Subquery) | ||
throw new InvalidOperationException ( | ||
$"NSExpressions of type {type} do not support the Predicate property. Expressions that support the property " | ||
+ "are of type Conditional and Subquery"); | ||
return _Predicate; | ||
} | ||
} | ||
|
||
[Export ("expressionBlock")] | ||
public virtual NSExpressionCallbackHandler Block { | ||
get { | ||
if (ExpressionType != NSExpressionType.Block) | ||
throw new InvalidOperationException ( | ||
$"NSExpressions of type {ExpressionType} do not support the Block property. Expressions that support the property " | ||
+ "are created via the FromFunction (NSExpressionHandler target, NSExpression[] parameters) method."); | ||
return _Block; | ||
} | ||
} | ||
|
||
[Export ("constantValue")] | ||
public virtual NSObject ConstantValue { | ||
get { | ||
if (ExpressionType != NSExpressionType.ConstantValue) | ||
throw new InvalidOperationException ( | ||
$"NSExpressions of type {ExpressionType} do not support the ConstantValue property. Expressions that support the property " | ||
+ "are created via the FromConstant methods."); | ||
return _ConstantValue; | ||
} | ||
} | ||
|
||
[Export ("keyPath")] | ||
public virtual string KeyPath { | ||
get { | ||
if (ExpressionType != NSExpressionType.KeyPath) | ||
throw new InvalidOperationException ( | ||
$"NSExpressions of type {ExpressionType} do not support the KeyPath property. Expressions that support the property " | ||
+ "are created via the FromKeyPath method."); | ||
return _KeyPath; | ||
} | ||
} | ||
|
||
[Export ("leftExpression")] | ||
public virtual NSExpression LeftExpression { | ||
get { | ||
var type = ExpressionType; | ||
if (type != NSExpressionType.Conditional && type != NSExpressionType.IntersectSet && type != NSExpressionType.MinusSet | ||
&& type != NSExpressionType.Subquery && type != NSExpressionType.UnionSet) | ||
throw new InvalidOperationException ( | ||
$"NSExpressions of type {type} do not support the LeftExpression property. Expressions that support the property " | ||
+ "are of type Conditional, IntersectSet, MinusSet, Subquery or UnionSet"); | ||
return _LeftExpression; | ||
} | ||
} | ||
|
||
[Mac(10,11),iOS(9,0)] | ||
[Export ("trueExpression")] | ||
public virtual NSExpression TrueExpression { | ||
get { | ||
var type = ExpressionType; | ||
if (type != NSExpressionType.Conditional && type != NSExpressionType.Subquery) | ||
throw new InvalidOperationException ( | ||
$"NSExpressions of type {type} do not support the TrueExpression property. Expressions that support the property " | ||
+ "are of type Conditional and Subquery"); | ||
return _TrueExpression; | ||
} | ||
} | ||
|
||
[Mac(10,11),iOS(9,0)] | ||
[Export ("falseExpression")] | ||
public virtual NSExpression FalseExpression { | ||
get { | ||
var type = ExpressionType; | ||
if (type != NSExpressionType.Conditional && type != NSExpressionType.Subquery) | ||
throw new InvalidOperationException ( | ||
$"NSExpressions of type {type} do not support the FalseExpression property. Expressions that support the property " | ||
+ "are of type Conditional and Subquery"); | ||
return _FalseExpression; | ||
} | ||
} | ||
|
||
[Export ("rightExpression")] | ||
public virtual NSExpression RightExpression { | ||
get { | ||
var type = ExpressionType; | ||
if (type != NSExpressionType.Conditional && type != NSExpressionType.IntersectSet && type != NSExpressionType.MinusSet | ||
&& type != NSExpressionType.Subquery && type != NSExpressionType.UnionSet) | ||
throw new InvalidOperationException ( | ||
$"NSExpressions of type {type} do not support the RightExpression property. Expressions that support the property " | ||
+ "are of type Conditional, IntersectSet, MinusSet, Subquery or UnionSet"); | ||
return _RightExpression; | ||
} | ||
} | ||
|
||
[Export ("function")] | ||
public virtual string Function { | ||
get { | ||
if (ExpressionType != NSExpressionType.Function) | ||
throw new InvalidOperationException ( | ||
$"NSExpressions of type {ExpressionType} do not support the Function property. Expressions that support the property " | ||
+ "are created via the FromFunction (FromFunction (string name, NSExpression[] parameters) or FromFormat methods."); | ||
return _Function; | ||
} | ||
} | ||
|
||
[Export ("variable")] | ||
public virtual string Variable { | ||
get { | ||
if (ExpressionType != NSExpressionType.Variable) | ||
throw new InvalidOperationException ( | ||
$"NSExpressions of type {ExpressionType} do not support the Function property. Expressions that support the property " | ||
+ "are created via the FromVariable method."); | ||
return _Variable; | ||
} | ||
} | ||
|
||
[Export ("operand")] | ||
public virtual NSExpression Operand { | ||
get { | ||
var type = ExpressionType; | ||
if (type != NSExpressionType.KeyPath && type != NSExpressionType.Function) | ||
throw new InvalidOperationException ( | ||
$"NSExpressions of type {type} do not support the Arguments property. Expressions that support the property " | ||
+ "are of type Function, Block and KeyPath"); | ||
return _Operand; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters