PropertyInfo[] properties = type.GetProperties().Select(x => x.DeclaringType.ToString() == "CrazyNinjaBadger");
Select(...)の実装を返しますIEnumerable<T>。コンパイラ エラーは非常に明白です。
もう 1 つのポイントは、プロパティをフィルター処理することです。.Select(...)列挙型を同じまたは他の型の別の型に射影するためのものです。
例えば:
IEnumerable<string> strings = new string[] { "0", "1" };
// Converting the string enumerable to an enumerable of integers:
IEnumerable<int> integers = strings.Select(some => int.Parse(some));
// Also, convert each strings into an anonymous object!
IEnumerable<object> whoKnows = strings.Select(some => new { Value = some });
列挙型をフィルタリングするには、を使用する必要があります.Where(...)。
一方、x.DeclaringType.ToString() == "CrazyNinjaBadger"は正しいですが、そうあるべきです(プロパティがあるx.DeclaringType.Name == "CrazyNinjaBadger"ため、型を文字列に変換する必要はありません)。TypeName
最後に、結果を配列に設定する必要はないと主張します。これを行うだけで済みます。
IEnumerable<PropertyInfo> properties =
type.GetProperties()
.Where(x => x.DeclaringType.Name == "CrazyNinjaBadger");