linq IEnumerable不包含'Length'的定义

hsvhsicv  于 2022-12-06  发布在  其他
关注(0)|答案(2)|浏览(175)
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?)

I have this error using Unity 2018 when i try to compile with .Net instead of IL2CPP This is the line where i get the error:

if (methods[i].GetCustomAttributes(typeof(CompilerGeneratedAttribute), true).Length != 0)
            {
                continue;
            }

And, in this other method:

var ret = (Delegate.CreateDelegate(typeof(V), target, method) as V);

also, in this method i used methodinfo instead of Delegate. but then ask about no method using 3 values.
Also added "using system.Linq"
Best regards

rlcwz9us

rlcwz9us1#

实际上,您希望测试IEnumerable<T>中是否有 * 任何 * 项:

if (methods[i].GetCustomAttributes(typeof(CompilerGeneratedAttribute), true).Any())
 {
     continue;
 }

如果坚持使用Length != 0方法,正确的语法是

if (methods[i].GetCustomAttributes(typeof(CompilerGeneratedAttribute), true).Count() > 0)
 {
     continue;
 }
fhity93d

fhity93d2#

好的,现在这样做很好:

if (methods[i].GetCustomAttributes(typeof(CompilerGeneratedAttribute), true).Count() > 0)

现在好了,对方错误在:

var ret = (Delegate.CreateDelegate(typeof(V), target, method) as V);

我尝试使用MethodInfo,但不起作用。“Delegate”不包含“CreateDelegate”的定义

相关问题