private void FillUpBoundPropertyEntry(BoundPropertyEntry entry, string name) { // Grab a member info corresponding to the property string objectModelName; MemberInfo memberInfo = PropertyMapper.GetMemberInfo(_controlType, name, out objectModelName); entry.Name = objectModelName; // If we got a memberInfo if (memberInfo != null) { if (memberInfo is PropertyInfo) { // If it's a property, make sure it is persistable PropertyInfo propInfo = ((PropertyInfo)memberInfo); if (propInfo.GetSetMethod() == null) { if (!SupportsAttributes) { throw new HttpException(SR.GetString(SR.Property_readonly, name)); } else { // If the property is readonly, fall back to using SetAttribute if (entry.TwoWayBound) { entry.ReadOnlyProperty = true; } else { entry.UseSetAttribute = true; } } } else { // The property is settable, so we can use it entry.PropertyInfo = propInfo; entry.Type = propInfo.PropertyType; } } else { // If it's a field, just grab the type Debug.Assert(memberInfo is FieldInfo); entry.Type = ((FieldInfo)memberInfo).FieldType; } } // If we didn't find a member, we need to use the IAttributeAccessor else { if (!SupportsAttributes) { throw new HttpException(SR.GetString(SR.Type_doesnt_have_property, _controlType.FullName, name)); } else { if (entry.TwoWayBound) { throw new InvalidOperationException(SR.GetString(SR.ControlBuilder_TwoWayBindingNonProperty, name, ControlType.Name)); } entry.Name = name; entry.UseSetAttribute = true; } } // Make sure we have parsed expression data if (entry.ParsedExpressionData == null) { entry.ParseExpression(new ExpressionBuilderContext(VirtualPath)); } if (!Parser.IgnoreParseErrors && entry.ParsedExpressionData == null) { // Disallow empty expressions (VSWhidbey 234273) if (Util.IsWhiteSpaceString(entry.Expression)) { throw new HttpException( SR.GetString(SR.Empty_expression)); } } }
private void FillUpBoundPropertyEntry(BoundPropertyEntry entry, string name) { string str; MemberInfo info = PropertyMapper.GetMemberInfo(this._controlType, name, out str); entry.Name = str; if (info != null) { if (info is PropertyInfo) { PropertyInfo info2 = (PropertyInfo) info; if (info2.GetSetMethod() == null) { if (!this.SupportsAttributes) { throw new HttpException(System.Web.SR.GetString("Property_readonly", new object[] { name })); } if (entry.TwoWayBound) { entry.ReadOnlyProperty = true; } else { entry.UseSetAttribute = true; } } else { entry.PropertyInfo = info2; entry.Type = info2.PropertyType; } } else { entry.Type = ((FieldInfo) info).FieldType; } } else { if (!this.SupportsAttributes) { throw new HttpException(System.Web.SR.GetString("Type_doesnt_have_property", new object[] { this._controlType.FullName, name })); } if (entry.TwoWayBound) { throw new InvalidOperationException(System.Web.SR.GetString("ControlBuilder_TwoWayBindingNonProperty", new object[] { name, this.ControlType.Name })); } entry.Name = name; entry.UseSetAttribute = true; } if (entry.ParsedExpressionData == null) { entry.ParseExpression(new ExpressionBuilderContext(this.VirtualPath)); } if ((!this.Parser.IgnoreParseErrors && (entry.ParsedExpressionData == null)) && System.Web.UI.Util.IsWhiteSpaceString(entry.Expression)) { throw new HttpException(System.Web.SR.GetString("Empty_expression")); } }