Si Grégoire codait en C# avec Linq, voilà ce que ça donnerait

Si Grégoire codait en C# avec Linq, voilà ce que ça donnerait


A force d’enseigner Linq, je voulais changer un peu, voila donc une façon originale de l’apprendre  via les paroles de la chanson “Toi+Moi” façon C# 😀 (et il a raison, la chanson est bien niaise)

 

 

 

 

void Launch()
{
var group1 = GetGroup((p) => p.InsoucianceAsync());
Action1(group1);
var group2 = GetGroup((p) => p.LuckyDay = DateTime.Now.Date);
Action2(group2);
group1 = GetGroup((p) => p.InsoucianceAsync());
Action3(group1);
group2 = GetGroup((p) => p.LuckyDay = DateTime.Now.Date);
Action4(group2);
group1 = GetGroup((p) => p.InsoucianceAsync());
group2 = GetGroup((p) => p.LuckyDay = DateTime.Now.Date);
var group3 = GetGroup((p) => { while (true) { Danse.Add(p); } });
}

private IEnumerable GetGroup(Action callback = null)
{
var firstGroup = (from person in People
where person.Id == YourId || person.Id == MyId
|| (person.Id != MyId && person.Id != YourId)
|| person.DoWant()
select person
).Distinct();
var secondGroup = (from person in People
where person.Id == HimId || person.Id == HerId
|| !person.Friends.Any()
select person
).Distinct();
var group = firstGroup.Union(secondGroup);
Danse.Concat(group);
if (callback != null)
group.AsParallel().ForAll(p => callback(p));
return group;
}

private void Action1(IEnumerable group)
{
if (group.Count() == 2 || group.Count() == 1000)
{
Actions.ForEach(
action => { action.CanHappen = action.Possible = true; });
var newPosY = Reve.Position.Y - delta;
var newPosX = Greve.Position.X + delta;
group.AsParallel().ForAll(person =>
{
person.Position = new Geocoordinate() { Y = newPosY, X = newPosX };
});
}
}

private void Action2(IEnumerable group)
{
if (!RetrieveDesire() || RetrieveStrength() || RetrieveBravery())
return;
var me = (from person in People where person.Id == MyId select person).First();
var withoutme = group.Except(new List() { me });
withoutme.AsParallel().ForAll(p => p.WaitOne());
Cold.SetAsMiracle();
Fear.SetAsMiracle();
Misfortune.Dispose();
me.WaitOne();
withoutme.AsParallel().ForAll(p => p.Release());
}

private void Action3(IEnumerable group)
{
var me = (from person in People where person.Id == MyId select person).First();
var mysong = Songs.First(p => p.Owner == me);
if (!(mysong.IsNaive && mysong.Style == SongStyle.Stupid && mysong.IsHarmless))
throw new Exception("can't occur");

var exWorld = World.Clone();
World.Give(mysong);
if (World.Equals(exWorld))
RoundDancing.GiveInvitation(group);
}

private void Action4(IEnumerable group2)
{
Hope.TakeAll();
Ardor.TakeAll();
var me = (from person in People where person.Id == MyId select person).First();

Hope.Take(me.Arms);
Hope.Take(me.Heart);
Hope.Take(me.Shoulders);
Hope.Take(me.Back);
Ardor.Take(me.Arms);
Ardor.Take(me.Heart);
Ardor.Take(me.Shoulders);
Ardor.Take(me.Back);
var you = (from person in People where person.Id == YourId select person).First();

var innerObject = me.Look(you.Eyes);
return innerObject.Exists(inobj => inobj is Star) && !me.IsSubmitted() && !you.IsSubmitted() && me.IsHappy() && you.IsHappy();
}

Comments are closed.