示例#1
0
 private static IList <PropertyData> GetPropertyList(Type t)
 {
     lock (ValuePropertyLists) {
         if (
             ValuePropertyLists.TryGetValue(
                 t,
                 out IList <PropertyData> ret))
         {
             return(ret);
         }
         ret = new List <PropertyData>();
         bool anonymous = HasCustomAttribute(
             t,
             "System.Runtime.CompilerServices.CompilerGeneratedAttribute");
         var names = new Dictionary <string, int>();
         foreach (PropertyInfo pi in GetTypeProperties(t))
         {
             var pn = RemoveIsPrefix(pi.Name);
             if (names.ContainsKey(pn))
             {
                 ++names[pn];
             }
             else
             {
                 names[pn] = 1;
             }
         }
         foreach (PropertyInfo pi in GetTypeProperties(t))
         {
             if (pi.CanRead && (pi.CanWrite || anonymous) &&
                 pi.GetIndexParameters().Length == 0)
             {
                 if (PropertyData.HasUsableGetter(pi) ||
                     PropertyData.HasUsableSetter(pi))
                 {
                     var pn = RemoveIsPrefix(pi.Name);
                     // Ignore ambiguous properties
                     if (names.ContainsKey(pn) && names[pn] > 1)
                     {
                         continue;
                     }
                     PropertyData pd = new PropertyMap2.PropertyData()
                     {
                         Name = pi.Name,
                         Prop = pi
                     };
                     ret.Add(pd);
                 }
             }
         }
         ValuePropertyLists.Add(t, ret);
         return(ret);
     }
 }