2009-08-28 14 views

cevap

38

, bir dizinli özellik var:

foreach (PropertyInfo pi in typeof(MyClass).GetProperties()) 
{ 
    if (pi.GetIndexParameters().Length > 0) 
    { 
     // Indexed property... 
    } 
} 
+0

+1 (Hala yazıyordum) – MaLio

4

Tür düzeyinde tanımlanmış DefaultMemberAttribute modelini arayın.

(Bu IndexerNameAttribute eskiden, ama bunu düştü gibi görünüyor)

Ayrıca o 0'dan fazla öğe döndürürse, PropertyInfo.GetIndexParameters yöntemi kullanılarak, endeks parametreleri için bakabilirsiniz
+0

'DefaultMemberAttribute' gerekli değildir referans bir dizin yapar, bu [cevap] (bkz https://stackoverflow.com/a/1119949/1161635). Beni dövdüğünüz için – Herman

3
static void Main(string[] args) { 

     foreach (System.Reflection.PropertyInfo propertyInfo in typeof(System.Collections.ArrayList).GetProperties()) { 

      System.Reflection.ParameterInfo[] parameterInfos = propertyInfo.GetIndexParameters(); 
      // then is indexer property 
      if (parameterInfos.Length > 0) { 
       System.Console.WriteLine(propertyInfo.Name); 
      } 
     } 


     System.Console.ReadKey(); 
    } 
İlgili konular