小编Lee*_*Lee的帖子

什么是.NETCore(Windows 8 Framework)的`GetCustomAttributes`的等效方法?

我正在整理一个与Stack API接口的应用程序,并且一直在关注本教程(虽然旧的API版本仍然有效).我的问题是,在Windows 8商店应用程序中使用它时,我受.NETCore Framework的限制,它不支持GetCustomAttributes下面找到的方法:

    private static IEnumerable<T> ParseJson<T>(string json) where T : class, new()
    {
        var type = typeof (T);
        var attribute = type.GetCustomAttributes(typeof (WrapperObjectAttribute), false).SingleOrDefault() as WrapperObjectAttribute;
        if (attribute == null)
        {
            throw new InvalidOperationException(
                String.Format("{0} type must be decorated with a WrapperObjectAttribute.", type.Name));
        }

        var jobject = JObject.Parse(json);
        var collection = JsonConvert.DeserializeObject<List<T>>(jobject[attribute.WrapperObject].ToString());
        return collection;
    }
Run Code Online (Sandbox Code Playgroud)

我的问题是双重的.GetCustomAttributes在Windows 8 Store App领域的限制范围内,该方法究竟做了什么以及与此方法等效?

.net c# windows-8 windows-runtime .net-core

34
推荐指数
1
解决办法
1万
查看次数

标签 统计

.net ×1

.net-core ×1

c# ×1

windows-8 ×1

windows-runtime ×1