1
어떻게 인터셉트 된 메소드의 리턴 타입을 얻을 수 있습니까? 메소드 레벨 캐싱 메커니즘을 작성 중이며 postsharp를 사용하여 메소드 호출을 가로 채고 싶습니다. 그러나, 내 저장된 개체를 원래 메서드 형식으로 캐스팅 할 수 있어야합니다. 대신 사용포스트 샤프가 인터셉트 된 메소드 리턴 타입
public override void OnEntry(MethodExecutionArgs InterceptedItem)
{
if (_instance==null)
_instance = new CouchbaseClient();
string Key = GetCacheKey(InterceptedItem);
var CacheItem = _instance.Get(Key);
if (CacheItem != null)
{
// The value was found in cache. Don't execute the method. Return immediately.
//string StringType = (String)_instance.Get(Key+"Type");
JavaScriptSerializer jss = new JavaScriptSerializer();
InterceptedItem.ReturnValue = jss.Deserialize<Object>(CacheItem.ToString());
//Type Type = Type.GetType(StringType);
InterceptedItem.ReturnValue = (Object)InterceptedItem.ReturnValue;
// jss.Deserialize(CacheItem.ToString(), Type.GetType(StringType));
InterceptedItem.FlowBehavior = FlowBehavior.Return;
}
else
{
// The value was NOT found in cache. Continue with method execution, but store
// the cache key so that we don't have to compute it in OnSuccess.
InterceptedItem.MethodExecutionTag = Key;
}
}
코드를 표시하십시오. 지금까지 뭐 해봤 어? 코드의 어느 시점에서 캐싱 된 객체를 캐스팅해야합니까? – Markus
InterceptedItem.ReturnValue = jss.Deserialize
jss.Deserialize