Zapis LINQ w tradycyjny jednolinijkowy sposób pisania kod:
var firstNumberSelector = GetNumbers().Where(x => x > 0).
ToLookup(x => x.ToString().First()).Select(x => new{x.Key, Items = x,Count = x.Distinct().Count()}).ToList();
A tutaj mój sposób pisania kodu:
var firstNumberSelector = GetNumbers()
.Where(x => x > 0)
.ToLookup(x => x.ToString()
.First())
.Select(x=>new {x.Key,
Items=x,
Count=x.Distinct()
.Count()})
.ToList();
Projekt Fluent NHibernate korzysta z takiego zapisu i kod może wyglądać tak:
_SessionFactory = Fluently
.Configure()
.Database(MsSqlCeConfiguration
.Standard
.ConnectionString("Data Source=MyDb.sdf")
.ShowSql()
)
.Mappings(m => m.FluentMappings
.AddFromAssemblyOf<NHibernateHelper>())
.ExposeConfiguration(cfg => new SchemaExport(cfg)
.Create(true, true) //create table in db
)
.Cache(c=>c
.UseSecondLevelCache()
.UseQueryCache()
.ProviderClass<HashtableCacheProvider>()
)
.BuildSessionFactory();
Dla mnie jest to kod bardziej czytelny i łatwiej mi jest określić jaka metoda jest uruchamiana dla danego obiektu.
Może Tobie też spodoba się taki sposób pisania kodu.
Brak komentarzy:
Prześlij komentarz