【发布时间】:2012-09-30 15:38:15
【问题描述】:
我正在制作一个与 Stack API 交互的应用程序,并且一直在关注 this tutorial(尽管旧的 API 版本仍然有效)。我的问题是,在 Windows 8 Store App 中使用它时,我受到 .NETCore 框架的限制,它不支持下面的 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;
}
我的问题有两个。 GetCustomAttributes 究竟做了什么,在 Windows 8 应用商店应用领域的限制内是否有与此方法等效的方法?
【问题讨论】:
标签: c# .net windows-8 windows-runtime .net-core