Created
September 15, 2014 06:53
-
-
Save ODataTeam/5245d34e73d2bfe6a3e0 to your computer and use it in GitHub Desktop.
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
class StringRepResolver : ODataUriResolver | |
{ | |
public override void PromoteBinaryOperandTypes( | |
BinaryOperatorKind binaryOperatorKind, | |
ref SingleValueNode leftNode, | |
ref SingleValueNode rightNode, | |
out IEdmTypeReference typeReference) | |
{ | |
if (binaryOperatorKind == BinaryOperatorKind.Multiply | |
&& leftNode.TypeReference != null | |
&& leftNode.TypeReference.IsString() | |
&& rightNode.TypeReference != null | |
&& rightNode.TypeReference.IsInt32()) | |
{ | |
// The result type should be Edm.String, as it could be nullable or not, we just took the left | |
// node's type reference. | |
typeReference = leftNode.TypeReference; | |
return; | |
} | |
// fallback | |
base.PromoteBinaryOperandTypes(binaryOperatorKind, ref leftNode, ref rightNode, out typeReference); | |
} | |
} |
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
// Usage of StringRepResolver | |
var parser = new ODataUriParser( | |
extModel.Model, | |
ServiceRoot, | |
new Uri("http://demo/odata.svc/People?$filter=Name eq 'Red' mul 3")); | |
try | |
{ | |
// Should throw exception | |
var clause = parser.ParseFilter(); | |
} | |
catch (Exception ex) | |
{ | |
Console.WriteLine(ex); | |
} | |
var parser2 = new ODataUriParser( | |
extModel.Model, | |
ServiceRoot, | |
new Uri("http://demo/odata.svc/People?$filter=Name eq 'Red' mul 3")) | |
{ | |
Resolver = new StringRepResolver() | |
}; | |
// Should work | |
var clause2 = parser2.ParseFilter(); | |
Console.WriteLine(clause2.Expression.ToLogString()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment