今天写了一段很简单的代码,但一直都有问题。代码如下.
接口定义
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace aoptest
{
interface ISay
{
void Say(string name);
}
}
实现
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace aoptest
{
class MySay : ISay
{
public void Say(string name)
{
Console.WriteLine("fuck off" + name);
}
}
}
代理调用
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Spring.Context.Support;
using Spring.Context;
using Spring.Aop.Framework;
namespace aoptest
{
class Program
{
static void Main(string[] args)
{
ProxyFactory factory = new ProxyFactory(new MySay());
factory.AddAdvice(new MyInterceptor());
Object o = factory.GetProxy ();
if (o is ISay) {
ISay m = o as ISay;
Console.WriteLine (m.ToString ());
} else {
Console.WriteLine ("not my say");
}
}
}
}
这么简单都代码,一直都运行失败,输出“not my say”.
其实很简单,原因就是:
接口应该定义为public的。
这个事情浪费了我两个小时!!!!
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/20966.html