• 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"/>
  • 相关阅读:
    iSCSI又称为IPSAN
    文档类型定义DTD
    HDU 2971 Tower
    HDU 1588 Gauss Fibonacci
    URAL 1005 Stone Pile
    URAL 1003 Parity
    URAL 1002 Phone Numbers
    URAL 1007 Code Words
    HDU 3306 Another kind of Fibonacci
    FZU 1683 纪念SlingShot
  • 原文地址:https://www.cnblogs.com/kexb/p/5919398.html
Copyright © 2020-2023  润新知