以下代码编译:
using Microsoft.SharePoint.Client class Dummy() { void DummyFunction(ClientContext ctx,ListCollection lists) { Context.Load(lists,lc => lc.Include(l => l.DefaultViewUrl); } }
但是,当切换到使用别名时,Include函数存在问题,这是一种扩展方法:
using SP = Microsoft.SharePoint.Client class DummyAliased() { void DummyFunction(SP.ClientContext ctx,SP.ListCollection lists) { /* Does not compile: */ Context.Load(lists,lc => lc.Include(l => l.DefaultViewUrl); /* Compiles (not using function as generic) */ Context.Load(lists,lc => SP.ClientObjectQueryableExtension.Include(lc,l => l.DefaultViewUrl)); } }
解决方法
不是在C#6之前…但是在C#6中你可以使用:
using static Microsoft.SharePoint.Client.ClientObjectQueryableExtension; using SP = Microsoft.SharePoint.Client;
其中第一个将只提供ClientObjectQueryableExtension的静态成员,而不与命名空间的其余部分有任何关系.