zoukankan      html  css  js  c++  java
  • Spring.net方法的替换

    1.为什么有时候你再执行某个方法的时候比如某个操作
    a.权限验证 b.任务执行
    当我执行到这个方法的时候,我可以先验证权限,如果验证不通过则替换到另一个方法去执行
    public class MyValueCalculator {
     public virtual string ComputeValue(string input) {
     // ... some real code
     }
     //
    2.代码实现
    替换类(含替换方法)的定义
    /// <summary>
    /// Meant to be used to override the existing ComputeValue(string)
    /// implementation in MyValueCalculator.
    /// </summary>
    public class ReplacementComputeValue : IMethodReplacer
    {
    public object Implement(object target, MethodInfo method, object[] arguments)
     {
     // get the input value, work with it, and return a computed result...
     string value = (string) arguments[0];
     // compute...
     return result;
     }
    }
    
    3.
    <object id="myValueCalculator" type="Examples.MyValueCalculator, ExampleAssembly">
     <!-- arbitrary method replacement -->
     <replaced-method name="ComputeValue" replacer="replacementComputeValue">
     <arg-type match="String"/>
     </replaced-method>
    </object>
    <object id="replacementComputeValue" type="Examples.ReplacementComputeValue, ExampleAssembly"/>
  • 相关阅读:
    HDU 2476 String painter (*区间DP+基础Dp)
    hdoj 1405 The Last Practice
    hdu 2715 Herd Sums
    hdu 3617 Happy 2009
    hdu 1062 Text Reverse
    hdu 2716 Message Decowding
    hdu 1597 find the nth digit
    hdoj 1229 还是A+B
    hdu 1877 又一版 A+B
    hdoj 2045 不容易系列之(3)—— LELE的RPG难题
  • 原文地址:https://www.cnblogs.com/kexb/p/5919398.html
Copyright © 2011-2022 走看看