Oregami
Repositories/oxedyne/fe2o3

oxedyne/fe2o3/fe2o3_text/tests/detect_corpus/csharp/canonical.txt

1.3 KiB, 1 run

created by r1870400018:11960, which is this file's identity for as long as the history lasts, whatever it is later renamed to

download · who wrote it · its history

1using System;
2using System.Collections.Generic;
3using System.Linq;
4
5namespace Annealer.Examples
6{
7 public class Registry<T>
8 {
9 private readonly Dictionary<string, T> _entries = new();
10 private readonly string _name;
11
12 public Registry(string name)
13 {
14 _name = name;
15 }
16
17 public void Register(string key, T value)
18 {
19 if (_entries.ContainsKey(key))
20 throw new ArgumentException($"duplicate key: {key}");
21 _entries[key] = value;
22 }
23
24 public T? Lookup(string key)
25 {
26 return _entries.TryGetValue(key, out var value) ? value : default;
27 }
28
29 public bool Contains(string key) => _entries.ContainsKey(key);
30 public int Count => _entries.Count;
31
32 public override string ToString()
33 => $"Registry[{_name}, {_entries.Count} entries]";
34 }
35
36 class Program
37 {
38 static void Main(string[] args)
39 {
40 var reg = new Registry<string>("colours");
41 reg.Register("red", "#ff0000");
42 reg.Register("green", "#00ff00");
43 reg.Register("blue", "#0000ff");
44
45 Console.WriteLine(reg);
46 Console.WriteLine($"red = {reg.Lookup("red")}");
47 }
48 }
49}