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
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<WrapperObjectAttribute>();
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.
Add the System.Reflection.TypeExtensions nugget package to your project; it has GetCustomAttributes extension.
(for VS 2017) something like this.
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard1.6'">
<PackageReference Include="System.Reflection.TypeExtensions">
<Version>4.3.0</Version>
</PackageReference>
</ItemGroup>