public static T GetCount <T>(this ICounterRegistry registry, string name) { Counter counter; if (!registry.TryCount(name, out counter)) { return(default(T)); } return(counter.ValueAs <T>()); }
public static bool Add <TCounter>(this ICounterRegistry registry, string name) where TCounter : ICounter { var ctor = typeof(TCounter).GetConstructor(new Type[] { typeof(string) }); if (ctor == null) { throw new ArgumentException(); } var counter = (ICounter)ctor.Invoke(new object[] { name }); return(registry.Add(counter)); }
public static bool TryCount <T>(this ICounterRegistry registry, string name, out T value) { ICounter counter; if (!registry.TryCount(name, out counter)) { value = default(T); return(false); } value = counter.ValueAs <T>(); return(true); }