c# - IEnumerable 不包含“长度”的定义
问题描述
error CS1061: 'IEnumerable<Attribute>' does not contain a definition for 'Length' and no extension method 'Length' accepting a first argument of type 'IEnumerable<Attribute>' could be found (are you missing a using directive or an assembly reference?)
当我尝试使用 .Net 而不是 IL2CPP 进行编译时,使用 Unity 2018 时出现此错误 这是我收到错误的行:
if (methods[i].GetCustomAttributes(typeof(CompilerGeneratedAttribute), true).Length != 0)
{
continue;
}
并且,在另一种方法中:
var ret = (Delegate.CreateDelegate(typeof(V), target, method) as V);
另外,在这种方法中,我使用了 methodinfo 而不是 Delegate。但随后询问没有使用 3 个值的方法。
还添加了“使用 system.Linq”
此致
解决方案
实际上,您想测试是否有任何项目在IEnumerable<T>
:
if (methods[i].GetCustomAttributes(typeof(CompilerGeneratedAttribute), true).Any())
{
continue;
}
如果您坚持Length != 0
使用正确的语法是
if (methods[i].GetCustomAttributes(typeof(CompilerGeneratedAttribute), true).Count() > 0)
{
continue;
}
推荐阅读
- python-datetime - 将第二个数据帧的一部分重新采样为每半秒
- laravel - 堆栈字段未显示在 Laravel Nova 的创建/编辑页面中
- c# - 我正在尝试将两个文件作为列表或数组导入,然后比较列表一中的所有内容都在列表二中
- reactjs - react-select:在onChange期间从另一个Select清除所选值
- linux - 查找文本文件中的所有时间戳,并使用 SED 或 AWK linux 将此时间戳转换为 (UTC-5)
- sql - (Databricks SQL) 存储为 STRING (yyyyMMDD) 的日期无法将其转换为 DATE (yyyy-MM-DD)
- python - 是否可以从芹菜链返回累积的结果?
- docker - 如何授予非 root 用户对 kubernetes SBM flexvolume 挂载的写入权限?
- flutter - 现在哪些小部件现在显示在列表中
- c++ - int 在合并排序中引发分段错误