2016-07-19 24 views
0

を働いていない:Fody MethodDecorator私はFodyを用いる方法デコレータを作成しようとしていますが、それは私に次のエラーを与える

enter image description here

私があったように任意の名前空間内の私のIMethodDecoratorをラップしないように、特定の世話をしていますオンラインで多くの場所で言及しています。以下は、コンソールアプリケーションで試しているサンプルコードです。

IMethodDecorator

using System; 
using System.Reflection; 


    public interface IMethodDecorator 
    { 
     void OnEntry(MethodBase method); 
     void OnExit(MethodBase method); 
     void OnException(MethodBase method, Exception exception); 
    } 

MethodDecoratorAttribute

using System; 
using System.Diagnostics; 
using System.Reflection; 
using FODYPOC; 

// Atribute should be "registered" by adding as module or assembly custom attribute 
[module: MethodDecorator] 

namespace FODYPOC 
{ 
// Any attribute which provides OnEntry/OnExit/OnException with proper args 
    [AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Assembly | AttributeTargets.Module)] 
    public class MethodDecoratorAttribute : Attribute, IMethodDecorator 
    { 
     // instance, method and args can be captured here and stored in attribute instance fields 
     // for future usage in OnEntry/OnExit/OnException 

     public MethodDecoratorAttribute() { } 

     public void OnEntry(MethodBase method) 
     { 
      Console.WriteLine(); 
     } 

     public void OnExit(MethodBase method) 
     { 
      Console.WriteLine(); 
     } 

     public void OnException(MethodBase method, Exception exception) 
     { 
      Console.WriteLine(); 
     } 
    } 

    public class Sample 
    { 
     [MethodDecorator] 
     public void Method() 
     { 
      Debug.WriteLine("Your Code"); 
     } 
    } 
} 

誰かが正しい方向に私を指すことができます。実装が非常に簡単に見えて、私はどこかで非常にばかげたミスを犯していることを知っています。

答えて

0

明らかに最新版のMethodDecorator.Fody(現在バージョン0.9.0.6)は機能していませんでした。バージョンをバージョン0.8.1.1にダウングレードすると、私の問題が解決しました。

もう少し調査した結果、2つのバージョンでインターフェイスメソッドシグネチャが異なっていたようです。だから私は新しいパッケージを持っていたとき、それはパラメータとしてMethodBaseを期待していなかったし、それが期待するインターフェイスに一致するものを見つけられなかったため、エラーを投げていた。

関連する問題