using System;
using System.Collections.Generic;
using System.Linq;
namespace Fixtures
{
public class Person
{
public int Id { get; set; }
public string Name { get; set; }
public string Email { get; set; }
public Person(int id, string name, string email)
{
Id = id;
Name = name;
Email = email;
}
public override string ToString()
{
return $"{Name} <{Email}>";
}
}
public class Repository<T>
{
private readonly Dictionary<int, T> _items = new();
public void Add(int key, T item)
{
_items[key] = item;
}
public T? Find(int key)
{
return _items.TryGetValue(key, out var item) ? item : default;
}
public IEnumerable<T> GetAll()
{
return _items.Values.ToList();
}
}
public static class Helpers
{
public static int Add(int a, int b) => a + b;
public static IEnumerable<T> Filter<T>(IEnumerable<T> items, Func<T, bool> predicate)
{
return items.Where(predicate);
}
}
public class Program
{
public static void Main(string[] args)
{
var repo = new Repository<Person>();
repo.Add(1, new Person(1, "Alice", "alice@example.com"));
repo.Add(2, new Person(2, "Bob", "bob@example.com"));
var active = repo.GetAll();
foreach (var p in active)
{
Console.WriteLine(p);
}
Console.WriteLine($"3 + 4 = {Helpers.Add(3, 4)}");
}
}
}