C #: extension methods are not available using aliased using directive

The following code compiles:

using Microsoft.SharePoint.Client class Dummy() { void DummyFunction(ClientContext ctx, ListCollection lists) { Context.Load(lists, lc => lc.Include(l => l.DefaultViewUrl); } } 

However, when switching to using aliases, there is a problem with the Include function, which is an extension method:

 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)); } } 

The Include function can still be used, but not as an extension method. Is there a way to use it as an extension method without smoothing the use directive?

+7
c # extension-methods
source share
1 answer

Not until C # 6 ... but in C # 6 you can use:

 using static Microsoft.SharePoint.Client.ClientObjectQueryableExtension; using SP = Microsoft.SharePoint.Client; 

The first one will contain only the static members of ClientObjectQueryableExtension , available without any changes to the rest of the namespace.

+10
source share

All Articles