C#???????????????
??????????? ???????[ 2017/4/10 13:55:39 ] ??????????????????? .NET
????????????????????????????????????????????????????????????У????????ζ??????????????????????????????????????????????????????????????????????????????????????????????????????“????API”????????????????????“???????????”????????????????л??????
???????????????????
??????????????????????????漰???????????????????????????????????????????????????????и????????д??????????????Ч??????????????????????????????????.NET???к??????????á????????????????????????????????????
???????????????????
??????????????????????????????????????????????????????????????????????????????н?????????????????
???????????????????
????????????DEMO?????????????????????????????Ihandler?????????????AHandler??BHandler??CHandler???????????????PipelContext????
public interface IHandler
{
PipelContext DoAction(PipelContext pipelContext);
}
public class AHandler : IHandler
{
private IHandler NextHandler { get; set; }
public AHandler(IHandler nextHandler)
{
NextHandler = nextHandler;
}
public PipelContext DoAction(PipelContext pipelContext)
{
bool isNext = (pipelContext.Flag < 20) ? true : false;
pipelContext.request = "AA";
Console.WriteLine("my is " + pipelContext.request);
if (NextHandler != null && isNext)
{
NextHandler.DoAction(pipelContext);
}
return pipelContext;
}
}
public class BHandler : IHandler
{
private IHandler NextHandler { get; set; }
public BHandler(IHandler nextHandler)
{
NextHandler = nextHandler;
}
public PipelContext DoAction(PipelContext pipelContext)
{
bool isNext = (pipelContext.Flag < 10) ? true : false;
pipelContext.request = "BB";
Console.WriteLine("my is " + pipelContext.request);
if (NextHandler != null && isNext)
{
NextHandler.DoAction(pipelContext);
}
return pipelContext;
}
}
public class CHandler : IHandler
{
private IHandler NextHandler { get; set; }
public CHandler(IHandler nextHandler)
{
NextHandler = nextHandler;
}
public PipelContext DoAction(PipelContext pipelContext)
{
bool isNext = (pipelContext.Flag < 5) ? true : false;
pipelContext.request = "CC";
Console.WriteLine("my is " + pipelContext.request);
if (NextHandler != null && isNext)
{
NextHandler.DoAction(pipelContext);
}
return pipelContext;
}
}
public class PipelContext
{
public PipelContext()
{
Key = Guid.NewGuid();
}
public Guid Key { get; set; }
public int Flag { get; set; }
public string request { get; set; }
public string respone { get; set; }
}
static void Main(string[] args)
{
IHandler ModuleC = new CHandler(null);
IHandler ModuleB = new BHandler(ModuleC);
IHandler ModuleA = new AHandler(ModuleB);
PipelContext p = new PipelContext();
while (true)
{
p.Flag = Convert.ToInt32(Console.ReadLine());
ModuleA.DoAction(p);
}
}
??????????
????????????????????????????????????и??????????????????????÷??????????????????????????????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11