首页 > 解决方案 > Asp.Core 中的 WebApi 1.0 动作重载

问题描述

WebApi 1.0 支持像这样的动作重载

public class BarsController : ApiController 
{ 

// /api/bars?h=hello 
public IEnumerable<string> Get(string h) 
{ 
return Get(h, null, null); 
} 
// /api/bars?h=hello&w=world 
public IEnumerable<string> Get(string h, string w) 
{ 
return Get(h, w, null); 
} 
// /api/bars?h=hello&w=world&z=15 
public IEnumerable<string> Get(string h, string w, int? z) 
{ 
if (z != 0) 
return new string[] { h, w, "this is z: " + z.ToString() }; 
else 
return new string[] { h, w }; 
} 
} 

据我所知,在 Asp.Core Api 中实现相同的逻辑是不可能的。所以,也许有人知道为什么这是不好的并且在 ASP.CORE 中不允许的任何充分理由,或者可能如何实现相同的行为 ASP.CORE 2.+ ?

标签: c#asp.net-web-apiasp.net-core-webapi

解决方案


推荐阅读