1- /* Copyright 2010-2015 MongoDB Inc.
1+ /* Copyright 2010-2016 MongoDB Inc.
22*
33* Licensed under the Apache License, Version 2.0 (the "License");
44* you may not use this file except in compliance with the License.
1919using System . Globalization ;
2020using System . Linq ;
2121using System . Linq . Expressions ;
22+ using System . Reflection ;
2223using System . Text . RegularExpressions ;
2324using MongoDB . Bson ;
2425using MongoDB . Bson . Serialization ;
@@ -329,7 +330,9 @@ private IMongoQuery BuildComparisonQuery(Expression variableExpression, Expressi
329330 var unaryExpression = variableExpression as UnaryExpression ;
330331 if ( unaryExpression != null && ( unaryExpression . NodeType == ExpressionType . Convert || unaryExpression . NodeType == ExpressionType . ConvertChecked ) )
331332 {
332- if ( unaryExpression . Operand . Type . IsEnum )
333+ var unaryExpressionTypeInfo = unaryExpression . Type . GetTypeInfo ( ) ;
334+ var unaryExpressionOperandTypeInfo = unaryExpression . Operand . Type . GetTypeInfo ( ) ;
335+ if ( unaryExpressionOperandTypeInfo . IsEnum )
333336 {
334337 var enumType = unaryExpression . Operand . Type ;
335338 if ( unaryExpression . Type == Enum . GetUnderlyingType ( enumType ) )
@@ -339,14 +342,14 @@ private IMongoQuery BuildComparisonQuery(Expression variableExpression, Expressi
339342 }
340343 }
341344 else if (
342- unaryExpression . Type . IsGenericType &&
343- unaryExpression . Type . GetGenericTypeDefinition ( ) == typeof ( Nullable < > ) &&
344- unaryExpression . Operand . Type . IsGenericType &&
345- unaryExpression . Operand . Type . GetGenericTypeDefinition ( ) == typeof ( Nullable < > ) &&
346- unaryExpression . Operand . Type . GetGenericArguments ( ) [ 0 ] . IsEnum )
345+ unaryExpressionTypeInfo . IsGenericType &&
346+ unaryExpressionTypeInfo . GetGenericTypeDefinition ( ) == typeof ( Nullable < > ) &&
347+ unaryExpressionOperandTypeInfo . IsGenericType &&
348+ unaryExpressionOperandTypeInfo . GetGenericTypeDefinition ( ) == typeof ( Nullable < > ) &&
349+ unaryExpressionOperandTypeInfo . GetGenericArguments ( ) [ 0 ] . GetTypeInfo ( ) . IsEnum )
347350 {
348- var enumType = unaryExpression . Operand . Type . GetGenericArguments ( ) [ 0 ] ;
349- if ( unaryExpression . Type . GetGenericArguments ( ) [ 0 ] == Enum . GetUnderlyingType ( enumType ) )
351+ var enumType = unaryExpressionOperandTypeInfo . GetGenericArguments ( ) [ 0 ] ;
352+ if ( unaryExpressionTypeInfo . GetGenericArguments ( ) [ 0 ] == Enum . GetUnderlyingType ( enumType ) )
350353 {
351354 serializationInfo = _serializationInfoHelper . GetSerializationInfo ( unaryExpression . Operand ) ;
352355 if ( value != null )
@@ -449,8 +452,9 @@ private IMongoQuery BuildContainsAnyQuery(MethodCallExpression methodCallExpress
449452 private IMongoQuery BuildContainsKeyQuery ( MethodCallExpression methodCallExpression )
450453 {
451454 var dictionaryType = methodCallExpression . Object . Type ;
452- var implementedInterfaces = new List < Type > ( dictionaryType . GetInterfaces ( ) ) ;
453- if ( dictionaryType . IsInterface )
455+ var dictionaryTypeInfo = dictionaryType . GetTypeInfo ( ) ;
456+ var implementedInterfaces = new List < Type > ( dictionaryTypeInfo . GetInterfaces ( ) ) ;
457+ if ( dictionaryTypeInfo . IsInterface )
454458 {
455459 implementedInterfaces . Add ( dictionaryType ) ;
456460 }
@@ -459,9 +463,10 @@ private IMongoQuery BuildContainsKeyQuery(MethodCallExpression methodCallExpress
459463 Type dictionaryInterface = null ;
460464 foreach ( var implementedInterface in implementedInterfaces )
461465 {
462- if ( implementedInterface . IsGenericType )
466+ var implementedInterfaceTypeInfo = implementedInterface . GetTypeInfo ( ) ;
467+ if ( implementedInterfaceTypeInfo . IsGenericType )
463468 {
464- if ( implementedInterface . GetGenericTypeDefinition ( ) == typeof ( IDictionary < , > ) )
469+ if ( implementedInterfaceTypeInfo . GetGenericTypeDefinition ( ) == typeof ( IDictionary < , > ) )
465470 {
466471 dictionaryGenericInterface = implementedInterface ;
467472 }
@@ -633,6 +638,7 @@ private IMongoQuery BuildEqualsQuery(MethodCallExpression methodCallExpression)
633638 private IMongoQuery BuildInQuery ( MethodCallExpression methodCallExpression )
634639 {
635640 var methodDeclaringType = methodCallExpression . Method . DeclaringType ;
641+ var methodDeclaringTypeInfo = methodDeclaringType . GetTypeInfo ( ) ;
636642 var arguments = methodCallExpression . Arguments . ToArray ( ) ;
637643 BsonSerializationInfo serializationInfo = null ;
638644 ConstantExpression valuesExpression = null ;
@@ -654,12 +660,13 @@ private IMongoQuery BuildInQuery(MethodCallExpression methodCallExpression)
654660 }
655661 else
656662 {
657- if ( methodDeclaringType . IsGenericType )
663+ if ( methodDeclaringTypeInfo . IsGenericType )
658664 {
659- methodDeclaringType = methodDeclaringType . GetGenericTypeDefinition ( ) ;
665+ methodDeclaringType = methodDeclaringTypeInfo . GetGenericTypeDefinition ( ) ;
666+ methodDeclaringTypeInfo = methodDeclaringType . GetTypeInfo ( ) ;
660667 }
661668
662- bool contains = methodDeclaringType == typeof ( ICollection < > ) || methodDeclaringType . GetInterface ( "ICollection`1" ) != null ;
669+ bool contains = methodDeclaringType == typeof ( ICollection < > ) || methodDeclaringTypeInfo . GetInterface ( "ICollection`1" ) != null ;
663670 if ( contains && arguments . Length == 1 )
664671 {
665672 serializationInfo = _serializationInfoHelper . GetSerializationInfo ( arguments [ 0 ] ) ;
@@ -1148,10 +1155,10 @@ private IMongoQuery BuildStringCaseInsensitiveComparisonQuery(Expression variabl
11481155 {
11491156 var stringValue = serializedValue . AsString ;
11501157 var stringValueCaseMatches =
1151- methodName == "ToLower" && stringValue == stringValue . ToLower ( CultureInfo . InvariantCulture ) ||
1152- methodName == "ToLowerInvariant" && stringValue == stringValue . ToLower ( CultureInfo . InvariantCulture ) ||
1153- methodName == "ToUpper" && stringValue == stringValue . ToUpper ( CultureInfo . InvariantCulture ) ||
1154- methodName == "ToUpperInvariant" && stringValue == stringValue . ToUpper ( CultureInfo . InvariantCulture ) ;
1158+ methodName == "ToLower" && stringValue == stringValue . ToLowerInvariant ( ) ||
1159+ methodName == "ToLowerInvariant" && stringValue == stringValue . ToLowerInvariant ( ) ||
1160+ methodName == "ToUpper" && stringValue == stringValue . ToUpperInvariant ( ) ||
1161+ methodName == "ToUpperInvariant" && stringValue == stringValue . ToUpperInvariant ( ) ;
11551162
11561163 if ( stringValueCaseMatches )
11571164 {
0 commit comments