@@ -26,6 +26,7 @@ internal class LinqExpressionVisitor : ExpressionVisitor
2626 [ typeof ( ICollection ) ] = new ICollectionResolver ( ) ,
2727 [ typeof ( IGrouping < , > ) ] = new GroupingResolver ( ) ,
2828 [ typeof ( Enumerable ) ] = new EnumerableResolver ( ) ,
29+ [ typeof ( MemoryExtensions ) ] = new MemoryExtensionsResolver ( ) ,
2930 [ typeof ( Guid ) ] = new GuidResolver ( ) ,
3031 [ typeof ( Math ) ] = new MathResolver ( ) ,
3132 [ typeof ( Regex ) ] = new RegexResolver ( ) ,
@@ -182,6 +183,13 @@ protected override Expression VisitMember(MemberExpression node)
182183 /// </summary>
183184 protected override Expression VisitMethodCall ( MethodCallExpression node )
184185 {
186+ if ( this . IsSpanImplicitConversion ( node . Method ) )
187+ {
188+ this . Visit ( node . Arguments [ 0 ] ) ;
189+
190+ return node ;
191+ }
192+
185193 // if special method for index access, eval index value (do not use parameters)
186194 if ( this . IsMethodIndexEval ( node , out var obj , out var idx ) )
187195 {
@@ -757,5 +765,30 @@ private bool TryGetResolver(Type declaringType, out ITypeResolver typeResolver)
757765
758766 return _resolver . TryGetValue ( type , out typeResolver ) ;
759767 }
768+
769+ private bool IsSpanImplicitConversion ( MethodInfo method )
770+ {
771+ if ( method == null || method . Name != "op_Implicit" || method . GetParameters ( ) . Length != 1 )
772+ {
773+ return false ;
774+ }
775+
776+ var returnType = method . ReturnType ;
777+
778+ return this . IsSpanLike ( returnType ) ;
779+ }
780+
781+ private bool IsSpanLike ( Type type )
782+ {
783+ if ( type == null || ! type . IsGenericType )
784+ {
785+ return false ;
786+ }
787+
788+ var definition = type . GetGenericTypeDefinition ( ) ;
789+ var name = definition . FullName ;
790+
791+ return name == "System.Span`1" || name == "System.ReadOnlySpan`1" ;
792+ }
760793 }
761- }
794+ }
0 commit comments