What is an equivalent method to `GetCustomAttributes` for .NETCore (Windows 8 Framework)?

前端 未结 2 1574
无人共我
无人共我 2020-12-09 01:34

I\'m putting together an app that interfaces with Stack API and have been following this tutorial (although old API version it still works). My problem is that when using t

2条回答
  •  庸人自扰
    2020-12-09 02:09

    You need to use type.GetTypeInfo(), which then has various GetCustomAttribute methods (via extension methods), or there is .CustomAttributes which gives you the raw information (rather than materialized Attribute instances).

    For example:

    var attribute = type.GetTypeInfo().GetCustomAttribute();
    if(attribute == null)
    {
        ...
    }
    ...
    

    GetTypeInfo() is the pain of .NETCore for library authors ;p

    If .GetTypeInfo() doesn't appear, then add a using System.Reflection; directive.

提交回复
热议问题