有没有办法指定不同命名空间中的同名扩展方法使用哪种扩展方法?

Is there a way to specify which extension method to use for extension methods of the same name in different namespaces?

使用以下代码片段的简单示例:

using System.Data;
using CustomerNameSpace;
...
...
CDataSet.CustomerDataTable dtCustomer = GetCustomer();

var customersWithName = dtCustomer.AsEnumerable()
    .Where(x => x.Name != null)
    .CopyToDataTable();

出于某种原因,我的同事在 CustomerNameSpace 中创建了一个扩展方法 CopyToDataTable()

本例中的程序同时使用了命名空间 System.DataCustomerNameSpace

两者现在都包含扩展方法 CopyToDataTable()

在下面的示例代码段中,是否可以指定使用这两个命名空间中的哪些扩展方法?

如果您在代码中绝对需要这两个名称空间,唯一的区别方法是将方法作为 'normal' 静态方法而不是扩展方法来调用:

var customers = dtCustomer.AsEnumerable()
    .Where(x => x.Name != null);
CustomerNameSpace.MyExtensionsClass.CopyToDataTable(customers);