/* * Returns the PropertyInfo or FieldInfo corresponding to the * specified property name. */ internal static MemberInfo GetMemberInfo(Type ctrlType, string name, out string nameForCodeGen) { Type currentType = ctrlType; PropertyInfo propInfo = null; FieldInfo fieldInfo = null; string mappedName = MapNameToPropertyName(name); nameForCodeGen = null; int startIndex = 0; while (startIndex < mappedName.Length) // parse thru dots of object model to locate PropertyInfo { string propName; int index = mappedName.IndexOf(OM_CHAR, startIndex); if (index < 0) { propName = mappedName.Substring(startIndex); startIndex = mappedName.Length; } else { propName = mappedName.Substring(startIndex, index - startIndex); startIndex = index + 1; } BindingFlags flags = BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | BindingFlags.IgnoreCase; // try { propInfo = TargetFrameworkUtil.GetProperty(currentType, propName, flags); } catch (AmbiguousMatchException) { flags |= BindingFlags.DeclaredOnly; propInfo = TargetFrameworkUtil.GetProperty(currentType, propName, flags); } if (propInfo == null) // could not find a public property, look for a public field { fieldInfo = TargetFrameworkUtil.GetField(currentType, propName, flags); if (fieldInfo == null) { nameForCodeGen = null; break; } } propName = null; if (propInfo != null) // found a public property { currentType = propInfo.PropertyType; propName = propInfo.Name; } else // found a public field { currentType = fieldInfo.FieldType; propName = fieldInfo.Name; } // Throw if the type of not CLS-compliant (ASURT 83438) if (!IsTypeCLSCompliant(currentType)) { throw new HttpException(SR.GetString(SR.Property_Not_ClsCompliant, name, ctrlType.FullName, currentType.FullName)); } if (propName != null) { if (nameForCodeGen == null) { nameForCodeGen = propName; } else { nameForCodeGen += STR_OM_CHAR + propName; } } } if (propInfo != null) { return(propInfo); } else { return(fieldInfo); } }
internal static MemberInfo GetMemberInfo(Type ctrlType, string name, out string nameForCodeGen) { Type propertyType = ctrlType; PropertyInfo info = null; FieldInfo info2 = null; string str = MapNameToPropertyName(name); nameForCodeGen = null; int startIndex = 0; while (startIndex < str.Length) { string str2; int index = str.IndexOf('.', startIndex); if (index < 0) { str2 = str.Substring(startIndex); startIndex = str.Length; } else { str2 = str.Substring(startIndex, index - startIndex); startIndex = index + 1; } BindingFlags bindingAttr = BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance | BindingFlags.IgnoreCase; try { info = TargetFrameworkUtil.GetProperty(propertyType, str2, bindingAttr); } catch (AmbiguousMatchException) { bindingAttr |= BindingFlags.DeclaredOnly; info = TargetFrameworkUtil.GetProperty(propertyType, str2, bindingAttr); } if (info == null) { info2 = TargetFrameworkUtil.GetField(propertyType, str2, bindingAttr); if (info2 == null) { nameForCodeGen = null; break; } } str2 = null; if (info != null) { propertyType = info.PropertyType; str2 = info.Name; } else { propertyType = info2.FieldType; str2 = info2.Name; } if (!IsTypeCLSCompliant(propertyType)) { throw new HttpException(System.Web.SR.GetString("Property_Not_ClsCompliant", new object[] { name, ctrlType.FullName, propertyType.FullName })); } if (str2 != null) { if (nameForCodeGen == null) { nameForCodeGen = str2; } else { nameForCodeGen = nameForCodeGen + "." + str2; } } } if (info != null) { return(info); } return(info2); }