@@ -241,10 +241,13 @@ private IExpressionPart GetIsOdFilterPart(List<QueryNode> arguments)
241241 if ( ! ( arguments [ 0 ] is SingleValueNode sourceNode ) )
242242 throw new ArgumentException ( "Expected SingleValueNode for source node." ) ;
243243
244- if ( ! ( arguments [ 1 ] is ConstantNode typeNode ) )
245- throw new ArgumentException ( "Expected ConstantNode for type node." ) ;
244+ if ( arguments [ 1 ] is ConstantNode typeNode )
245+ return IsOf ( GetCastType ( typeNode ) ) ;
246246
247- return IsOf ( GetCastType ( typeNode ) ) ;
247+ if ( arguments [ 1 ] is SingleResourceCastNode singleResourceCastNode )
248+ return IsOf ( GetCastType ( singleResourceCastNode ) ) ;
249+
250+ throw new ArgumentException ( "Expected ConstantNode or SingleResourceCastNode for type node." ) ;
248251
249252 IExpressionPart IsOf ( Type conversionType )
250253 => new IsOfOperator ( GetFilterPart ( sourceNode ) , conversionType ) ;
@@ -255,14 +258,25 @@ private IExpressionPart GetCastResourceFilterPart(List<QueryNode> arguments)
255258 if ( ! ( arguments [ 0 ] is SingleValueNode sourceNode ) )
256259 throw new ArgumentException ( "Expected SingleValueNode for source node." ) ;
257260
258- if ( ! ( arguments [ 1 ] is ConstantNode typeNode ) )
259- throw new ArgumentException ( "Expected ConstantNode for type node." ) ;
261+ if ( arguments [ 1 ] is ConstantNode typeNode )
262+ {
263+ return Convert
264+ (
265+ GetClrType ( sourceNode . TypeReference ) ,
266+ GetCastType ( typeNode )
267+ ) ;
268+ }
260269
261- return Convert
262- (
263- GetClrType ( sourceNode . TypeReference ) ,
264- GetCastType ( typeNode )
265- ) ;
270+ if ( arguments [ 1 ] is SingleResourceCastNode singleResourceCastNode )
271+ {
272+ return Convert
273+ (
274+ GetClrType ( sourceNode . TypeReference ) ,
275+ GetCastType ( singleResourceCastNode )
276+ ) ;
277+ }
278+
279+ throw new ArgumentException ( "Expected ConstantNode or SingleResourceCastNode for type node." ) ;
266280
267281 IExpressionPart Convert ( Type operandType , Type conversionType )
268282 {
@@ -291,23 +305,36 @@ private IExpressionPart GetCastFilterPart(List<QueryNode> arguments)
291305 if ( ! ( arguments [ 0 ] is SingleValueNode sourceNode ) )
292306 throw new ArgumentException ( "Expected SingleValueNode for source node." ) ;
293307
294- if ( ! ( arguments [ 1 ] is ConstantNode typeNode ) )
295- throw new ArgumentException ( "Expected ConstantNode for type node." ) ;
308+ if ( arguments [ 1 ] is ConstantNode typeNode )
309+ {
310+ return Convert
311+ (
312+ GetClrType ( sourceNode . TypeReference ) ,
313+ GetCastType ( typeNode ) ,
314+ typeNode . TypeReference
315+ ) ;
316+ }
296317
297- return Convert
298- (
299- GetClrType ( sourceNode . TypeReference ) ,
300- GetCastType ( typeNode )
301- ) ;
318+ if ( arguments [ 1 ] is SingleResourceCastNode singleResourceCastNode )
319+ {
320+ return Convert
321+ (
322+ GetClrType ( sourceNode . TypeReference ) ,
323+ GetCastType ( singleResourceCastNode ) ,
324+ singleResourceCastNode . TypeReference
325+ ) ;
326+ }
302327
303- IExpressionPart Convert ( Type operandType , Type conversionType )
328+ throw new ArgumentException ( "Expected ConstantNode or SingleResourceCastNode for type node." ) ;
329+
330+ IExpressionPart Convert ( Type operandType , Type conversionType , IEdmTypeReference edmTypeReference )
304331 {
305332 if ( OperandIsNullConstant ( sourceNode ) || operandType == conversionType )
306333 return GetFilterPart ( sourceNode ) ;
307334
308335 if ( ShouldConvertTypes ( operandType , conversionType , sourceNode ) )
309336 {
310- if ( ( ! typeNode . TypeReference . IsPrimitive ( ) && ! typeNode . TypeReference . IsEnum ( ) )
337+ if ( ( ! edmTypeReference . IsPrimitive ( ) && ! edmTypeReference . IsEnum ( ) )
311338 || ( ! operandType . IsLiteralType ( ) && ! operandType . ToNullableUnderlyingType ( ) . IsEnum ) )
312339 return new ConstantOperator ( null ) ;
313340
@@ -345,6 +372,9 @@ IExpressionPart Convert(Type operandType, Type conversionType)
345372 private Type GetCastType ( ConstantNode constantNode )
346373 => TypeExtensions . GetClrType ( ( string ) constantNode . Value , false , typesCache ) ;
347374
375+ private Type GetCastType ( SingleResourceCastNode singleResourceCastNode )
376+ => TypeExtensions . GetClrType ( singleResourceCastNode . TypeReference , typesCache ) ;
377+
348378 private IExpressionPart GetCustomMehodFilterPart ( string functionName , SingleValueNode [ ] arguments )
349379 {
350380 MethodInfo methodInfo = CustomMethodCache . GetCachedCustomMethod ( functionName , arguments . Select ( p => GetClrType ( p . TypeReference ) ) ) ;
0 commit comments