【发布时间】:2018-11-06 19:56:06
【问题描述】:
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”
最好的问候
【问题讨论】:
-
你的问题是什么?
-
.Count()或.Any()可能是您想要的。 -
.Count()而不是Length;或(更好).Any()- 如果IEnumerable<T>中有任何项目 -
这是因为
IEnumerable不是任何长度。它只是一个方法GetEnumerator()的接口。通常会混淆IEnumerable是具有固定长度的某种类型的数组,但这不一定是而且通常不是这样。Array和List确实使用IEnumerable接口,但接口本身并不意味着存在任何项目。
标签: c#