我有以下代碼似乎沒有正確行事。有一個屬性有一個不屬於FieldMapAttribute
類型的屬性,但它仍會進入if條件,在此條件下我將檢查與該類型屬性匹配的計數。Lambda Expression - 它的評估是否正確?
foreach (PropertyInfo _property in _properties)
{
var attributes = _property.GetCustomAttributes(false);
if (attributes.Select(a => a.GetType() == typeof(FieldMapAttribute)).Count() > 0)
{
colname = (attributes.Select(a => a.GetType() == typeof(FieldMapAttribute)).Cast<FieldMapAttribute>().First()).DbColumnName;
}
}
有人能幫我理解這裏發生了什麼嗎?
@Downvoter謹慎解釋你的downvote? –
不是我的失望,但PropertyInfo.IsDefined是一個更簡單的測試方法。 –
這兩個答案都非常有幫助,我真的很感激Jon&Adi。感謝球員,我似乎再次順利運行。 –