• ProxyFactory的一个问题


    今天写了一段很简单的代码,但一直都有问题。代码如下.

    接口定义

    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的。
    

    这个事情浪费了我两个小时!!!!

  • 相关阅读:
    雅虎笔试&面试题
    有道面试
    IBM笔试&面试
    20140916~17华宇笔试&面试
    操作系统知识梳理3-存储管理
    操作系统知识梳理2-哲学家就餐问题
    操作系统知识梳理1-概述及进程管理
    阿里面试总结
    2012-2015网易有道笔试题总结
    PostgresSQL在cmd中使用psql操作数据库
  • 原文地址:https://www.cnblogs.com/wardensky/p/4816617.html
Copyright © 2020-2023  润新知