// bf default is DefaultLookup in the .net code for GetProperties() static public List <PropertyNameInfo> GetPropertyFieldNames(Type jtype, string prefix = "", BindingFlags bf = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public, bool fields = false, int linelen = 80, string comment = null) // give a list of properties for a given name { if (jtype != null) { List <PropertyNameInfo> ret = new List <PropertyNameInfo>(); foreach (System.Reflection.PropertyInfo pi in jtype.GetProperties(bf)) { if (pi.GetIndexParameters().GetLength(0) == 0) // only properties with zero parameters are called { PropertyNameInfo pni = PNI(prefix + pi.Name, pi.PropertyType, linelen, comment); ret.Add(pni); // System.Diagnostics.Debug.WriteLine("Prop " + pi.Name + " " + pi.PropertyType.FullName); } } if (fields) { foreach (FieldInfo fi in jtype.GetFields()) { PropertyNameInfo pni = PNI(prefix + fi.Name, fi.FieldType, linelen, comment); ret.Add(pni); // System.Diagnostics.Debug.WriteLine("Fields " + fi.Name + " " + fi.FieldType.FullName); } } return(ret); } else { return(null); } }
static public void AddToPNI(List <PropertyNameInfo> ret, Type pt, string name, object [] ca, BindingFlags bf, bool fields, int linelen, string comment, Type excludedeclaretype, Type[] propexcluded, bool excludearrayslist, int depth, string classsepar) { if (pt.IsArray) { if (excludearrayslist) { return; } Type arraytype = pt.GetElementType(); var pni = PNI(name + classsepar + "Count", typeof(int), 0, "Array Count", "Count of items. Use <name>[index, 1..N]" + classsepar + "itemname for particular item"); ret.Add(pni); var pnis = GetPropertyFieldNames(arraytype, name + "[]" + classsepar, bf, fields, linelen, comment, excludedeclaretype, propexcluded, excludearrayslist, depth - 1, classsepar); if (pnis != null) { ret.AddRange(pnis); } } else if ((typeof(System.Collections.IDictionary).IsAssignableFrom(pt))) { var pni = PNI(name + classsepar + "Count", typeof(int), 0, "Dictionary Count", "Count of items. Use <name>" + classsepar + "itemname for particular item"); } else if (typeof(System.Collections.IList).IsAssignableFrom(pt)) { if (excludearrayslist) { return; } var pni = PNI(name + classsepar + "Count", typeof(int), 0, "List Count", "Count of items. Use <name>[index, 1..N]" + classsepar + "itemname for particular item"); ret.Add(pni); var subclasslist = GetPropertyFieldNames(pt.GenericTypeArguments[0], name + "[]" + classsepar, bf, fields, linelen, comment, excludedeclaretype, propexcluded, excludearrayslist, depth - 1, classsepar); if (subclasslist != null) { ret.AddRange(subclasslist); } } else if (pt.IsClass && pt != typeof(string)) { var pni = GetPropertyFieldNames(pt, name + classsepar, bf, fields, linelen, comment, excludedeclaretype, propexcluded, excludearrayslist, depth - 1, classsepar); if (pni != null) { ret.AddRange(pni); } } else { string help = ca.Length > 0 ? ((dynamic)ca[0]).Text : ""; PropertyNameInfo pni = PNI(name, pt, linelen, comment, help); ret.Add(pni); } }