我正在整理一个与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领域的限制范围内,该方法究竟做了什么以及与此方法等效?