Example #1
0
 private static IList <PropertyData> GetPropertyList(Type t)
 {
     lock (ValuePropertyLists) {
         IList <PropertyData> ret;
         if (ValuePropertyLists.TryGetValue(t, out ret))
         {
             return(ret);
         }
         ret = new List <PropertyData>();
         bool anonymous = HasCustomAttribute(
             t,
             "System.Runtime.CompilerServices.CompilerGeneratedAttribute");
         foreach (PropertyInfo pi in GetTypeProperties(t))
         {
             if (pi.CanRead && (pi.CanWrite || anonymous) &&
                 pi.GetIndexParameters().Length == 0)
             {
                 PropertyData pd = new PropertyMap.PropertyData();
                 pd.Name = pi.Name;
                 pd.Prop = pi;
                 ret.Add(pd);
             }
         }
         ValuePropertyLists.Add(t, ret);
         return(ret);
     }
 }
Example #2
0
 private static IList<PropertyData> GetPropertyList(Type t) {
   lock (ValuePropertyLists) {
     IList<PropertyData> ret;
     if (ValuePropertyLists.TryGetValue(t, out ret)) {
       return ret;
     }
     ret = new List<PropertyData>();
     bool anonymous = t.Name.Contains("__AnonymousType");
     foreach (PropertyInfo pi in GetTypeProperties(t)) {
       if (pi.CanRead && (pi.CanWrite || anonymous) &&
       pi.GetIndexParameters().Length == 0) {
         PropertyData pd = new PropertyMap.PropertyData();
         pd.Name = pi.Name;
         // Convert 'IsXYZ' to 'XYZ'
         if (pd.Name.Length >= 3 && pd.Name[0] == 'I' && pd.Name[1] == 's' &&
             pd.Name[2] >= 'A' && pd.Name[2] == 'Z') {
           pd.Name = pd.Name.Substring(2);
         }
         // Convert to camel case
         if (pd.Name[0] >= 'A' && pd.Name[0] <= 'Z') {
           var sb = new System.Text.StringBuilder();
           sb.Append((char)(pd.Name[0] + 0x20));
           sb.Append(pd.Name.Substring(1));
           pd.Name = sb.ToString();
         }
         pd.Prop = pi;
         ret.Add(pd);
       }
     }
     ValuePropertyLists.Add(t, ret);
     return ret;
   }
 }
Example #3
0
 private static IList <PropertyData> GetPropertyList(Type t)
 {
     lock (ValuePropertyLists) {
         IList <PropertyData> ret = new List <PropertyData>();
         if (ValuePropertyLists.ContainsKey(t))
         {
             return(ValuePropertyLists[t]);
         }
         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 PropertyMap.PropertyData()
                     {
                         Name = pi.Name,
                         Prop = pi,
                     };
                     ret.Add(pd);
                 }
             }
         }
         ValuePropertyLists.Add(t, ret);
         return(ret);
     }
 }
Example #4
0
 private static IList <PropertyData> GetPropertyList(Type t)
 {
     lock (ValuePropertyLists) {
         IList <PropertyData> ret;
         if (ValuePropertyLists.TryGetValue(t, out ret))
         {
             return(ret);
         }
         ret = new List <PropertyData>();
         bool anonymous = HasCustomAttribute(
             t,
             "System.Runtime.CompilerServices.CompilerGeneratedAttribute");
         foreach (PropertyInfo pi in GetTypeProperties(t))
         {
             if (pi.CanRead && (pi.CanWrite || anonymous) &&
                 pi.GetIndexParameters().Length == 0)
             {
                 PropertyData pd = new PropertyMap.PropertyData();
                 pd.Name = pi.Name;
                 // Convert 'IsXYZ' to 'XYZ'
                 if (pd.Name.Length >= 3 && pd.Name[0] == 'I' && pd.Name[1] == 's' &&
                     pd.Name[2] >= 'A' && pd.Name[2] == 'Z')
                 {
                     pd.Name = pd.Name.Substring(2);
                 }
                 // Convert to camel case
                 if (pd.Name[0] >= 'A' && pd.Name[0] <= 'Z')
                 {
                     var sb = new System.Text.StringBuilder();
                     sb.Append((char)(pd.Name[0] + 0x20));
                     sb.Append(pd.Name.Substring(1));
                     pd.Name = sb.ToString();
                 }
                 pd.Prop = pi;
                 ret.Add(pd);
             }
         }
         ValuePropertyLists.Add(t, ret);
         return(ret);
     }
 }