C# Language Specification


The query expression pattern



Download 0,75 Mb.
bet279/524
Sana06.01.2022
Hajmi0,75 Mb.
#324842
1   ...   275   276   277   278   279   280   281   282   ...   524
Bog'liq
CSharp Language Specification

The query expression pattern


The Query expression pattern establishes a pattern of methods that types can implement to support query expressions. Because query expressions are translated to method invocations by means of a syntactic mapping, types have considerable flexibility in how they implement the query expression pattern. For example, the methods of the pattern can be implemented as instance methods or as extension methods because the two have the same invocation syntax, and the methods can request delegates or expression trees because anonymous functions are convertible to both.

The recommended shape of a generic type C that supports the query expression pattern is shown below. A generic type is used in order to illustrate the proper relationships between parameter and result types, but it is possible to implement the pattern for non-generic types as well.

delegate R Func(T1 arg1);

delegate R Func(T1 arg1, T2 arg2);

class C
{
public C Cast();
}

class C : C


{
public C Where(Func predicate);

public C Select(Func selector);

public C SelectMany(Func> selector,
Func resultSelector);

public C Join(C inner, Func outerKeySelector,


Func innerKeySelector, Func resultSelector);

public C GroupJoin(C inner, Func outerKeySelector,


Func innerKeySelector, Func,V> resultSelector);

public O OrderBy(Func keySelector);

public O OrderByDescending(Func keySelector);

public C> GroupBy(Func keySelector);

public C> GroupBy(Func keySelector,
Func elementSelector);
}

class O : C


{
public O ThenBy(Func keySelector);

public O ThenByDescending(Func keySelector);


}

class G : C


{
public K Key { get; }
}

The methods above use the generic delegate types Func and Func, but they could equally well have used other delegate or expression tree types with the same relationships in parameter and result types.

Notice the recommended relationship between C and O which ensures that the ThenBy and ThenByDescending methods are available only on the result of an OrderBy or OrderByDescending. Also notice the recommended shape of the result of GroupBy—a sequence of sequences, where each inner sequence has an additional Key property.

The System.Linq namespace provides an implementation of the query operator pattern for any type that implements the System.Collections.Generic.IEnumerable interface.



    1. Download 0,75 Mb.

      Do'stlaringiz bilan baham:
1   ...   275   276   277   278   279   280   281   282   ...   524




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish