I understand that you do not want to request an instance, but keep the method static. This is not possible, the static field is loaded once in the module and cannot be inherited.
I think the only way is to store the dictionary in a helper class, with the type as the key. Like this
class Helper { static Dictionary<Type,string> _urls; public static string GetUrl(Type ofType) { return _urls[ofType]; } public static void AddUrl(Type ofType, string url) { _urls.Add(ofType,url); } } class b { static b(){ Helper.AddUrl(typeof(b)," ");} } class Program { b result= doJSONRequest<b>(Helper.GetUrl(typeof(b)); }
Or you can decorate the desired types with a custom attribute and save the data in this attribute. Like this
class UrlAttribute:Attribute { public string Url{get;private set;} public UrlAttribute(string url){Url=url;} } [Url("someurl")] class b { } class Program { void Main() { UrlAttribute attr = (UrlAttribute)Attribute.GetCustomAttribute(typeof(b), typeof(UrlAttribute));
Of course, you can pass them all by reflecting and initializing the dictionary, see this question .
source share