zoukankan      html  css  js  c++  java
  • 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的。
    

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

  • 相关阅读:
    Redis学习
    extractor
    Linux fork exec等
    Linux kill 命令
    GCC参数使用
    Shell 参数(2) --解析命令行参数工具:getopts/getopt
    Shell 参数(1)
    shell 中并发执行
    Linux 下新增用户的流程
    Linux 安全rm
  • 原文地址:https://www.cnblogs.com/wardensky/p/4816617.html
Copyright © 2011-2022 走看看