mercredi 5 juillet 2017

Using System.Attribute as Route Attribute Reflection

I have attribute list but I want to get specific properties of each attribute. For examle I have action like

[HttpGet, Route("/autocomplete")]
[ActionInfo(Description = "bla bla bla blac")]
// GET: AutoComplete
public ActionResult AutoComplete()
{
    return View();
 }


 private static IEnumerable<Attribute> MyMethod(IEnumerable<Attribute> attributes)
 {
    foreach (Attribute attribute in attributes)
    {
        switch (attribute.GetType().Name)
        {
            case "HttpGetAttribute":
            {
                using (attribute as HttpGetAttribute)
                {
                    // my business
                }
                break;
            }
            case "RouteAttribute":
            {
                using (attribute as RouteAttribute)
                {
                    // my business
                }
                break;
            }
            case "ActionInfoAttribute":
            {
                using (attribute as ActionInfoAttribute)
                {
                    // my business
                }
                break;
            }
        }
    }

    return null;
}





Aucun commentaire:

Enregistrer un commentaire