public string ManipulatePerson(Person p, EndWork callback) { p.NumeroMani += 2; callback(p); return(p.Cognome); }
private WorkEnded RaiseEvent(EndWork command, string userId) { return(new WorkEnded { Id = command.WorkId, TimeyTaskId = command.TimeyTaskId, UserId = userId, EndTime = DateTime.UtcNow }); }
public async void Work(Patient patient) { if (patient is null) { throw new NullReferenceException(); } _patient = patient; await Task.Run(() => Thread.Sleep((int)patient.Time *Debug.UnitTime)); EndWork?.Invoke(this, new EventArgs()); }
public void Training() { Distance = 0; for (int i = 0; i < 10; i++) { Distance += 50; Thread.Sleep(1000); Console.WriteLine(Name + Surname + " is running " + Distance + " meters"); Console.WriteLine("Now his weight is " + Weight--); Console.WriteLine("Now his fifarate is " + qual.fifaRate++); } EndWork?.Invoke(); }
public void Run() { Calculate add = new Calculate(Add); Calculate sub = new Calculate(Sub); Console.WriteLine(DoCalculate(add)); Console.WriteLine(DoCalculate(sub)); //instanza delegate con lambda Calculate max = new Calculate((a, b) => { return(a > b ? a : b); }); int result = DoCalculate(max); Console.WriteLine(result); //parametro diretto come puntatore alla funzione DoCalculate(Max); //parametro diretto come expr. lambda DoCalculate((int a, int b) => { return(a * b); }); //stessa cosa per Func<int, int, int>, che è sempre un delegate DoCalculateFunc(Max); DoCalculateFunc((a, b) => { return(a * b); }); Person mario = new Person("Mario", "Rossi"); EndWork callback = new EndWork(EndWorkCallback); Console.WriteLine(ManipulatePerson(mario, callback)); }
public IEnumerable <EventBase> Handle(EndWork command, string userId) { if (command == null) { throw new ArgumentNullException(nameof(command)); } if (command.TimeyTaskId == Guid.Empty) { throw new ArgumentNullException(nameof(command.TimeyTaskId)); } if (command.WorkId == Guid.Empty) { throw new ArgumentNullException(nameof(command.WorkId)); } if (string.IsNullOrWhiteSpace(userId)) { throw new ArgumentNullException(nameof(userId)); } return(new List <EventBase> { RaiseEvent(command, userId) }); }
public override string ToString() { string tmeeting, tcontract, thourormonth; if (IsMeeting) { tmeeting = "yes"; } else { tmeeting = "no"; } if (IsContract) { tcontract = "yes"; } else { tcontract = "no"; } if (HourOrMonth) { thourormonth = "hour"; } else { thourormonth = "month"; } return("num contract: " + NumContract + "\nid child: " + IdChild + "\nage child: " + ageChild + "\nId mother: " + IdMom + "\nid nanny: " + IdNanny + "\nis meeting? " + tmeeting + "\nis contract? " + tcontract + "\nhour payment: " + HourPayment + "\nmonth payment: " + MonthPayment + "\nhour or month? " + thourormonth + "\nbegin date: " + BeginWork.ToString("dd/MM/yyyy") + "\nend date: " + EndWork.ToString("dd/MM/yyyy") + "\num hours per week: " + numHoursPerWeek); }
public void AskContinueFlag(string text) { Console.WriteLine(text); EndWork?.Invoke(this, new EventArgs()); }