protected static TTarget?LookUp <TTarget>(object?value) { if (value is null) { return((TTarget?)value); } else if (Convert((dynamic)value) is ValueTuple <TTarget> result) { return(result.Item1); } if (LookupTables.Get <TTarget>() is var table and not null) { switch (value) { case string s: return(table[s]); case Lookup lookup: return(table[lookup]); } } throw new InvalidOperationException($"Invalid {typeof(TTarget).Name} lookup: {value}"); }
public static T Get <T>(Lookup lookup) { var table = LookupTables.Get <T>(); if (table == null) { throw new ArgumentException($"Unsupported type {typeof(T).Name}", nameof(T)); } return(table[lookup]); }