public void Deny_Unrestricted () { DataBindingCollection dbc = new DataBindingCollection (); Assert.AreEqual (0, dbc.Count, "Count"); Assert.IsFalse (dbc.IsReadOnly, "IsReadOnly"); Assert.IsFalse (dbc.IsSynchronized, "IsSynchronized"); dbc.Add (db); Assert.AreSame (db, dbc["property"], "this[string]"); Assert.IsNotNull (dbc.RemovedBindings, "RemovedBindings"); Assert.IsNotNull (dbc.SyncRoot, "SyncRoot"); Assert.IsNotNull (dbc.GetEnumerator (), "GetEnumerator"); dbc.CopyTo (new DataBinding[1], 0); dbc.Clear (); dbc.Add (db); dbc.Remove (db); dbc.Add (db); dbc.Remove ("property"); dbc.Remove ("property", true); #if NET_2_0 dbc.Changed += new EventHandler (Handler); Assert.IsFalse (dbc.Contains ("property"), "Contains"); dbc.Changed -= new EventHandler (Handler); #endif }
private void InitBoundProperty(Control control, BoundPropertyEntry entry, ref DataBindingCollection dataBindings, ref IAttributeAccessor attributeAccessor) { if (entry.ExpressionPrefix.Length != 0) { throw new InvalidOperationException(System.Web.SR.GetString("ControlBuilder_ExpressionsNotAllowedInThemes")); } if ((dataBindings == null) && (control != null)) { dataBindings = ((IDataBindingsAccessor)control).DataBindings; } dataBindings.Add(new DataBinding(entry.Name, entry.Type, entry.Expression.Trim())); }
[Test] public void ChangeTest () { DataBindingCollection a = new DataBindingCollection (); a.Changed += delegate { changed = true; }; DataBinding b = new DataBinding ("a", typeof (DataBindingCollectionTest), "b"); a.Add (b); Assert.AreEqual (true, changed, "DB1"); changed = false; a.Clear (); Assert.AreEqual (false, changed, "DB2"); a.Remove (b); Assert.AreEqual (true, changed, "DB3"); }
private void InitBoundProperty(Control control, BoundPropertyEntry entry, ref DataBindingCollection dataBindings, ref IAttributeAccessor attributeAccessor) { string expressionPrefix = entry.ExpressionPrefix; // If we're in the designer, add the bound properties to the collections if (expressionPrefix.Length == 0) { if (dataBindings == null && control is IDataBindingsAccessor) { dataBindings = ((IDataBindingsAccessor)control).DataBindings; } dataBindings.Add(new DataBinding(entry.Name, entry.Type, entry.Expression.Trim())); } else { throw new InvalidOperationException(SR.GetString(SR.ControlBuilder_ExpressionsNotAllowedInThemes)); } }
private void InitBoundProperty(Control control, BoundPropertyEntry entry, ref DataBindingCollection dataBindings, ref IAttributeAccessor attributeAccessor) { string expressionPrefix = entry.ExpressionPrefix; // If we're in the designer, add the bound properties to the collections if (expressionPrefix.Length == 0) { if (dataBindings == null && control is IDataBindingsAccessor) { dataBindings = ((IDataBindingsAccessor)control).DataBindings; } dataBindings.Add(new DataBinding(entry.Name, entry.Type, entry.Expression.Trim())); } else { throw new InvalidOperationException(SR.GetString(SR.ControlBuilder_ExpressionsNotAllowedInThemes)); } }
private void InitBoundProperty(object obj, BoundPropertyEntry entry, ref DataBindingCollection dataBindings, ref IAttributeAccessor attributeAccessor) { string expressionPrefix = entry.ExpressionPrefix == null ? String.Empty : entry.ExpressionPrefix.Trim(); // If we're in the designer, add the bound properties to the collections if (InDesigner) { if (String.IsNullOrEmpty(expressionPrefix)) { if (dataBindings == null && obj is IDataBindingsAccessor) { dataBindings = ((IDataBindingsAccessor)obj).DataBindings; } dataBindings.Add(new DataBinding(entry.Name, entry.Type, entry.Expression.Trim())); } else { if (obj is IExpressionsAccessor) { string expression = entry.Expression == null ? String.Empty : entry.Expression.Trim(); ((IExpressionsAccessor)obj).Expressions.Add(new ExpressionBinding(entry.Name, entry.Type, expressionPrefix, expression, entry.Generated, entry.ParsedExpressionData)); } } } // If we're in no-compile mode, set the values for expressions that support evaluate else { if (!String.IsNullOrEmpty(expressionPrefix)) { ExpressionBuilder eb = entry.ExpressionBuilder; Debug.Assert(eb != null, "Did not expect null expression builder"); if (eb.SupportsEvaluate) { string name = entry.Name; // DevDiv Bugs 160497: Create the expression context with whatever information we have. // We used to always use the TemplateControl one, but sometimes it's null, so we should // fall back to the VirtualPath one if we can. ExpressionBuilderContext expressionContext; if (TemplateControl != null) { expressionContext = new ExpressionBuilderContext(TemplateControl); } else { expressionContext = new ExpressionBuilderContext(VirtualPath); } object value = eb.EvaluateExpression(obj, entry, entry.ParsedExpressionData, expressionContext); if (entry.UseSetAttribute) { if (attributeAccessor == null) { Debug.Assert(obj is IAttributeAccessor); attributeAccessor = (IAttributeAccessor)obj; } attributeAccessor.SetAttribute(name, value.ToString()); } else { try { PropertyMapper.SetMappedPropertyValue(obj, name, value, InDesigner); } catch (Exception e) { throw new HttpException(SR.GetString(SR.Cannot_set_property, entry.ExpressionPrefix + ":" + entry.Expression, name), e); } } } else { Debug.Fail("Got a ExpressionBuilder that does not support Evaluate in a non-compiled page"); } } else { // no-compile Bind property handling ((Control)obj).DataBinding += new EventHandler(DataBindingMethod); } } }
private void InitBoundProperty(object obj, BoundPropertyEntry entry, ref DataBindingCollection dataBindings, ref IAttributeAccessor attributeAccessor) { string str = (entry.ExpressionPrefix == null) ? string.Empty : entry.ExpressionPrefix.Trim(); if (this.InDesigner) { if (string.IsNullOrEmpty(str)) { if ((dataBindings == null) && (obj is IDataBindingsAccessor)) { dataBindings = ((IDataBindingsAccessor) obj).DataBindings; } dataBindings.Add(new DataBinding(entry.Name, entry.Type, entry.Expression.Trim())); } else if (obj is IExpressionsAccessor) { string expression = (entry.Expression == null) ? string.Empty : entry.Expression.Trim(); ((IExpressionsAccessor) obj).Expressions.Add(new ExpressionBinding(entry.Name, entry.Type, str, expression, entry.Generated, entry.ParsedExpressionData)); } } else { if (!string.IsNullOrEmpty(str)) { ExpressionBuilderContext context; ExpressionBuilder expressionBuilder = entry.ExpressionBuilder; if (!expressionBuilder.SupportsEvaluate) { return; } string name = entry.Name; if (this.TemplateControl != null) { context = new ExpressionBuilderContext(this.TemplateControl); } else { context = new ExpressionBuilderContext(this.VirtualPath); } object obj2 = expressionBuilder.EvaluateExpression(obj, entry, entry.ParsedExpressionData, context); if (entry.UseSetAttribute) { if (attributeAccessor == null) { attributeAccessor = (IAttributeAccessor) obj; } attributeAccessor.SetAttribute(name, obj2.ToString()); return; } try { PropertyMapper.SetMappedPropertyValue(obj, name, obj2, this.InDesigner); return; } catch (Exception exception) { throw new HttpException(System.Web.SR.GetString("Cannot_set_property", new object[] { entry.ExpressionPrefix + ":" + entry.Expression, name }), exception); } } ((Control) obj).DataBinding += new EventHandler(this.DataBindingMethod); } }
/* * Set all the properties we have on the passed in object * This is not called when generating code for compiling... it is * used in design-mode, and at runtime when the user calls Page.ParseControl */ internal void SetProperties(object obj) { Debug.Assert(_fInDesigner, "Expected to be running in design mode."); object[] parameters = new object[1]; IAttributeAccessor attributeAccessor = null; DataBindingCollection dataBindings = null; if (_fDataBound && (_entries.Count != 0)) { Debug.Assert(obj is Control, "SetProperties on databindings PropertySetter should only be called for controls."); dataBindings = ((IDataBindingsAccessor)obj).DataBindings; } // Get the supported attribute interfaces if (_fSupportsAttributes) { attributeAccessor = (IAttributeAccessor)obj; } IEnumerator en = _entries.GetEnumerator(); while (en.MoveNext()) { PropertySetterEntry entry = (PropertySetterEntry)en.Current; if (entry._propType == null) { if (entry._fItemProp) { try { object objValue = entry._builder.BuildObject(); parameters[0] = objValue; MethodInfo methodInfo = _objType.GetMethod("Add", BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static, null /*binder*/, new Type[] { objValue.GetType() }, null /*modifiers*/); Util.InvokeMethod(methodInfo, obj, parameters); } catch (Exception) { throw new HttpException( HttpRuntime.FormatResourceString(SR.Cannot_add_value_not_collection, entry._value)); } } else { // If there is no property, use SetAttribute if (attributeAccessor != null) { attributeAccessor.SetAttribute(entry._name, entry._value); } } } else { // Use the propinfo to set the prop // Use either _propValue or _builder, whichever is set if (entry._propValue != null) { try { PropertyMapper.SetMappedPropertyValue(obj, entry._name, entry._propValue); } catch (Exception e) { throw new HttpException( HttpRuntime.FormatResourceString(SR.Cannot_set_property, entry._value, entry._name), e); } } else if (entry._builder != null) { if (entry._fReadOnlyProp) { // a complex property is allowed to be readonly try { object objValue; // Get the property since its readonly MethodInfo methodInfo = entry._propInfo.GetGetMethod(); objValue = Util.InvokeMethod(methodInfo, obj, null); // now we need to initialize this property entry._builder.InitObject(objValue); } catch (Exception e) { throw new HttpException( HttpRuntime.FormatResourceString(SR.Cannot_init, entry._name), e); } } else { try { object objValue = entry._builder.BuildObject(); parameters[0] = objValue; // Set the property MethodInfo methodInfo = entry._propInfo.GetSetMethod(); Util.InvokeMethod(methodInfo, obj, parameters); } catch (Exception e) { throw new HttpException( HttpRuntime.FormatResourceString(SR.Cannot_set_property, entry._value, entry._name), e); } } } else if (dataBindings != null) { DataBinding binding = new DataBinding(entry._name, entry._propType, entry._value.Trim()); dataBindings.Add(binding); } else { Debug.Assert(false, "'" + entry._value + "' failed to be set on property '" + entry._name + "'."); } } } }
private void InitBoundProperty(Control control, BoundPropertyEntry entry, ref DataBindingCollection dataBindings, ref IAttributeAccessor attributeAccessor) { if (entry.ExpressionPrefix.Length != 0) { throw new InvalidOperationException(System.Web.SR.GetString("ControlBuilder_ExpressionsNotAllowedInThemes")); } if ((dataBindings == null) && (control != null)) { dataBindings = ((IDataBindingsAccessor) control).DataBindings; } dataBindings.Add(new DataBinding(entry.Name, entry.Type, entry.Expression.Trim())); }