По сути, я пытаюсь сделать следующее
Код: Выделить всё
abstract class Dao {
// some kind of static string called "CacheKeyStem". The below doesn't work because you can't have abstract static properties
abstract static string CacheKeyStem { get; }
int Id { get; set; }
string CacheKey => $"{CacheKeyStem}-{Id}";
}
PersonDao : Dao {
// override CacheKeyStem. Again, this doesn't work
public static override string CacheKeyStem => "Person";
}
CarDao : Dao {
// override CacheKeyStem. Again, this doesn't work
public static override string CacheKeyStem => "Car";
}
Код: Выделить всё
abstract class BaseProcessor where T : Dao {
public void AddToCache(T obj){
_myCache.Add(obj.CacheKey, obj);
}
public T RetrieveFromCache(int id){
// the below obviously doesnt work either.
return _myCache.Get($"{T.CacheKeyStem}-{id}");
}
}
Подробнее здесь: https://stackoverflow.com/questions/791 ... ument-in-c
Мобильная версия