1

我安装了 VS .NET 2010,以及一个面向 .NET 3.5 的类库。下面的简单 C# 片段在 .NET 4.0 的 peverify 下生成可验证的 IL,但 IL 不使用 .NET 3.5 的 peverify 进行验证。

在此过渡中是否修复了任何 peverify 错误?

public static bool IsGenericTypeInstance(this Type typ)
{
    return typ.IsGenericType && !typ.IsGenericTypeDefinition;
}
public static IEnumerable<Type> GetAllGenericArguments(this Type type)
{
    return type.IsGenericTypeInstance()
         ? type.GetGenericArguments()
               .SelectMany(x => x.IsGenericTypeInstance()
                                ? GetAllGenericArguments(x)
                                : new[] { x })
         : Enumerable.Empty<Type>();
}

产生的错误是:

Error   26  [Sasa.dll : Sasa.Types::<GetAllGenericArguments>b__0]
[offset 0x0000001C][found ref 'System.Collections.IEnumerable']
[expected ref 'System.Collections.Generic.IEnumerable`1[System.Type]']
Unexpected type on the stack.

我显然有点担心,因为我明确针对 .NET 3.5,并且我不希望在这个平台上出现运行时验证错误。

4

0 回答 0