/// <devdoc> /// <para>[To be supplied.]</para> /// </devdoc> public override void Init(TemplateParser parser, ControlBuilder parentBuilder, Type type, string tagName, string ID, IDictionary attribs) { base.Init(parser, parentBuilder, type /*type*/, tagName, ID, attribs); // PropertyInfo propInfo = TargetFrameworkUtil.GetProperty(parentBuilder.ControlType, tagName, BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | BindingFlags.IgnoreCase); SetControlType(propInfo.PropertyType); Debug.Assert(ControlType != null, "ControlType != null"); BindingFlags bindingFlags = BindingFlags.Public | BindingFlags.Instance; // Look for an "item" property on the collection that takes in an integer index // (similar to IList::Item) propInfo = TargetFrameworkUtil.GetProperty(ControlType, "Item", bindingFlags, types: new Type[] { typeof(int) }); if (propInfo == null) { // fall-back on finding a non-specific Item property // a type with overloaded indexed properties will result in an exception however propInfo = TargetFrameworkUtil.GetProperty(ControlType, "Item", bindingFlags); } // If we got one, use it to determine the type of the items if (propInfo != null) { _itemType = propInfo.PropertyType; } }
private bool IsVersion40OrAbove() { if (HostingEnvironment.IsHosted) { return(MultiTargetingUtil.IsTargetFramework40OrAbove); } return(TargetFrameworkUtil.IsSupportedType(typeof(TagRegex35))); }
internal static PropertyDescriptor GetMappedPropertyDescriptor(object obj, string mappedName, out object childObject, out string propertyName, bool inDesigner) { childObject = LocatePropertyObject(obj, mappedName, out propertyName, inDesigner); if (childObject == null) { return(null); } return(TargetFrameworkUtil.GetProperties(childObject)[propertyName]); }
private bool IsVersion40OrAbove() { if (HostingEnvironment.IsHosted) { // If we are running in a hosted environment, then we can simply check the target version. return(MultiTargetingUtil.IsTargetFramework40OrAbove); } else { // Otherwise, we are in the designer, and thus should check using the type description provider. // The new type TagRegex35 only exists when targeting 4.0 and above. return(TargetFrameworkUtil.IsSupportedType(typeof(TagRegex35))); } }
public override void Init(TemplateParser parser, ControlBuilder parentBuilder, Type type, string tagName, string ID, IDictionary attribs) { base.Init(parser, parentBuilder, type, tagName, ID, attribs); PropertyInfo info = TargetFrameworkUtil.GetProperty(parentBuilder.ControlType, tagName, BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance | BindingFlags.IgnoreCase); base.SetControlType(info.PropertyType); BindingFlags bindingAttr = BindingFlags.Public | BindingFlags.Instance; info = TargetFrameworkUtil.GetProperty(base.ControlType, "Item", bindingAttr, null, null, new Type[] { typeof(int) }, null); if (info == null) { info = TargetFrameworkUtil.GetProperty(base.ControlType, "Item", bindingAttr); } if (info != null) { this._itemType = info.PropertyType; } }
/* * 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); }