在下面的代码中,我想返回一个 IEnumerable 而不创建新的数据结构对象。但是,我收到以下代码的编译器错误。我错过了什么?
Error Cannot implicitly convert type 'System.Reflection.FieldInfo[]' to 'System.Reflection.FieldInfo'
public static IEnumerable<FieldInfo> GetAllFields(Type objectType)
{
while (objectType != null)
{
//GetFields(...) returns a FieldInfo []
yield return objectType.GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
objectType = objectType.BaseType;
}
}