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;
        }
    }
4

1 に答える 1