【发布时间】:2021-02-22 23:43:45
【问题描述】:
在自定义 HttpClient 的以下代码中,我发现一个方法接受一个接口并将其写入,就好像它是一个具有属性的对象:
public async Task<T> GetAsync<T>(ICacheContext cacheContext = null) {
try {
T result = default(T);
// check if value is cached
if (cacheContext != null) {
result = await GetResultFromCache<T>(cacheContext);
if (result != null) {
cacheContext.IsDataFromCache = true;
return result;
}
}
我对@987654322@ 有点困惑。为什么要设置接口的属性?这不是你要对所述接口的对象实现做的事情吗?
【问题讨论】:
-
cacheContext是ICacheContext的实现,它是一个对象,而不仅仅是一个接口 -
Isn't that something you'd do to the object implementation of said interface?那是字面意思代码在做什么。
标签: c# .net caching interface implementation