using Cronos;
using Newtonsoft.Json;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Reflection;
using System.Threading;
namespace ConsoleApp1
{
internal class Program
{
static void Main(string[] args)
{
var filters = new List<Filter> {
new Filter("A"),
new Filter("B"),
};
var fn = filters.GetEnumerator();
InvokeNext(ref fn);
Console.WriteLine("All filters have been invoked.");
}
static void InvokeNext(ref List<Filter>.Enumerator filters)
{
if (filters.MoveNext())
{
InvokeCurrent(ref filters);
return;
}
Console.WriteLine("调起真正的运行方法.");
}
static void InvokeCurrent(ref List<Filter>.Enumerator filters)
{
var current = filters.Current;
current.Before();
InvokeNext(ref filters);
current.After();
}
}
class Filter
{
private string name;
public Filter(string name)
{
this.name = name;
}
public void Before()
{
Console.WriteLine("Before filter " + name);
}
public void Current()
{
Console.WriteLine("Current filter " + name);
}
public void After()
{
Console.WriteLine("After filter " + name);
}
}
}
输出:
Before filter A
Before filter B
调起真正的运行方法.
After filter B
After filter A
All filters have been invoked.
标签:filter,name,void,System,Filter,管道,filters,using
From: https://www.cnblogs.com/readafterme/p/18390297