示例#1
0
		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 static bool CanSerializeAsInnerDefaultString(string filter, string name, Type type, ObjectPersistData persistData, PersistenceMode mode, DataBindingCollection dataBindings, ExpressionBindingCollection expressions)
 {
     if (((((type == typeof(string)) && (filter.Length == 0)) && ((mode == PersistenceMode.InnerDefaultProperty) || (mode == PersistenceMode.EncodedInnerDefaultProperty))) && ((dataBindings == null) || (dataBindings[name] == null))) && ((expressions == null) || (expressions[name] == null)))
     {
         if (persistData == null)
         {
             return true;
         }
         ICollection propertyAllFilters = persistData.GetPropertyAllFilters(name);
         if (propertyAllFilters.Count == 0)
         {
             return true;
         }
         if (propertyAllFilters.Count == 1)
         {
             foreach (PropertyEntry entry in propertyAllFilters)
             {
                 if ((entry.Filter.Length == 0) && (entry is ComplexPropertyEntry))
                 {
                     return true;
                 }
             }
         }
     }
     return false;
 }
        private void ApplyBoundProperties(Control control)
        {
            DataBindingCollection dataBindings      = null;
            IAttributeAccessor    attributeAccessor = null;

            foreach (BoundPropertyEntry entry in base.GetFilteredPropertyEntrySet(this._skinBuilder.BoundPropertyEntries))
            {
                this.InitBoundProperty(control, entry, ref dataBindings, ref attributeAccessor);
            }
        }
 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()));
 }
示例#5
0
        private void ApplyBoundProperties(Control control)
        {
            DataBindingCollection dataBindings      = null;
            IAttributeAccessor    attributeAccessor = null;

            // If there are no filters in the picture, use the entries as is
            ICollection entries = GetFilteredPropertyEntrySet(_skinBuilder.BoundPropertyEntries);

            foreach (BoundPropertyEntry entry in entries)
            {
                InitBoundProperty(control, entry, ref dataBindings, ref attributeAccessor);
            }
        }
示例#6
0
		[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");
		}
示例#7
0
        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 static void SerializeAttributesRecursive(object obj, IDesignerHost host, string prefix, ObjectPersistData persistData, string filter, ArrayList attributes, DataBindingCollection dataBindings, ExpressionBindingCollection expressions, bool topLevelInDesigner)
 {
     PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(obj);
     if (obj is IDataBindingsAccessor)
     {
         dataBindings = ((IDataBindingsAccessor) obj).DataBindings;
     }
     if (obj is Control)
     {
         try
         {
             ControlCollection controls = ((Control) obj).Controls;
         }
         catch (Exception exception)
         {
             IComponentDesignerDebugService service = host.GetService(typeof(IComponentDesignerDebugService)) as IComponentDesignerDebugService;
             if (service != null)
             {
                 service.Fail(exception.Message);
             }
         }
     }
     if (obj is IExpressionsAccessor)
     {
         expressions = ((IExpressionsAccessor) obj).Expressions;
     }
     for (int i = 0; i < properties.Count; i++)
     {
         try
         {
             SerializeAttribute(obj, properties[i], dataBindings, expressions, host, prefix, persistData, filter, attributes, topLevelInDesigner);
         }
         catch (Exception exception2)
         {
             if (host != null)
             {
                 IComponentDesignerDebugService service2 = host.GetService(typeof(IComponentDesignerDebugService)) as IComponentDesignerDebugService;
                 if (service2 != null)
                 {
                     service2.Fail(exception2.Message);
                 }
             }
         }
     }
 }
 private static void SerializeAttribute(object obj, PropertyDescriptor propDesc, DataBindingCollection dataBindings, ExpressionBindingCollection expressions, IDesignerHost host, string prefix, ObjectPersistData persistData, string filter, ArrayList attributes, bool topLevelInDesigner)
 {
     DesignOnlyAttribute attribute = (DesignOnlyAttribute) propDesc.Attributes[typeof(DesignOnlyAttribute)];
     if ((attribute == null) || !attribute.IsDesignOnly)
     {
         string name = propDesc.Name;
         Type propertyType = propDesc.PropertyType;
         PersistenceMode mode = ((PersistenceModeAttribute) propDesc.Attributes[typeof(PersistenceModeAttribute)]).Mode;
         bool flag = (dataBindings != null) && (dataBindings[name] != null);
         bool flag2 = (expressions != null) && (expressions[name] != null);
         if (((flag || flag2) || (propDesc.SerializationVisibility != DesignerSerializationVisibility.Hidden)) && (((mode == PersistenceMode.Attribute) || ((flag && flag2) && (propertyType == typeof(string)))) || ((mode != PersistenceMode.InnerProperty) && (propertyType == typeof(string)))))
         {
             string str2 = string.Empty;
             if (prefix.Length > 0)
             {
                 str2 = prefix + "-" + name;
             }
             else
             {
                 str2 = name;
             }
             if (propDesc.SerializationVisibility == DesignerSerializationVisibility.Content)
             {
                 SerializeAttributesRecursive(propDesc.GetValue(obj), host, str2, persistData, filter, attributes, dataBindings, expressions, topLevelInDesigner);
             }
             else
             {
                 IAttributeAccessor accessor = obj as IAttributeAccessor;
                 if (!propDesc.IsReadOnly || ((accessor != null) && (accessor.GetAttribute(str2) != null)))
                 {
                     string str3 = ConvertPersistToObjectModelName(str2);
                     if (!FilterableAttribute.IsPropertyFilterable(propDesc))
                     {
                         filter = string.Empty;
                     }
                     if (CanSerializeAsInnerDefaultString(filter, str3, propertyType, persistData, mode, dataBindings, expressions))
                     {
                         if (topLevelInDesigner)
                         {
                             attributes.Add(new Triplet(filter, str2, null));
                         }
                     }
                     else
                     {
                         bool flag3 = true;
                         object objB = null;
                         object objA = propDesc.GetValue(obj);
                         BindingType none = BindingType.None;
                         if (dataBindings != null)
                         {
                             DataBinding binding = dataBindings[str3];
                             if (binding != null)
                             {
                                 objA = binding.Expression;
                                 none = BindingType.Data;
                             }
                         }
                         if (none == BindingType.None)
                         {
                             if (expressions != null)
                             {
                                 ExpressionBinding binding2 = expressions[str3];
                                 if ((binding2 != null) && !binding2.Generated)
                                 {
                                     objA = binding2.ExpressionPrefix + ":" + binding2.Expression;
                                     none = BindingType.Expression;
                                 }
                             }
                             else if (persistData != null)
                             {
                                 BoundPropertyEntry filteredProperty = persistData.GetFilteredProperty(filter, name) as BoundPropertyEntry;
                                 if ((filteredProperty != null) && !filteredProperty.Generated)
                                 {
                                     objB = GetPropertyDefaultValue(propDesc, str2, persistData, filter, host);
                                     if (object.Equals(objA, objB))
                                     {
                                         objA = filteredProperty.ExpressionPrefix + ":" + filteredProperty.Expression;
                                         none = BindingType.Expression;
                                     }
                                 }
                             }
                         }
                         if (filter.Length == 0)
                         {
                             bool useResult = false;
                             bool flag5 = false;
                             if (none == BindingType.None)
                             {
                                 flag5 = GetShouldSerializeValue(obj, name, out useResult);
                             }
                             if (useResult)
                             {
                                 flag3 = flag5;
                             }
                             else
                             {
                                 objB = GetPropertyDefaultValue(propDesc, str2, persistData, filter, host);
                                 flag3 = !object.Equals(objA, objB);
                             }
                         }
                         else
                         {
                             objB = GetPropertyDefaultValue(propDesc, str2, persistData, filter, host);
                             flag3 = !object.Equals(objA, objB);
                         }
                         if (flag3)
                         {
                             string z = GetPersistValue(propDesc, propertyType, objA, none, topLevelInDesigner);
                             if (((topLevelInDesigner && (objB != null)) && ((z == null) || (z.Length == 0))) && ShouldPersistBlankValue(objB, propertyType))
                             {
                                 z = string.Empty;
                             }
                             if ((z != null) && (!propertyType.IsArray || (z.Length > 0)))
                             {
                                 attributes.Add(new Triplet(filter, str2, z));
                             }
                             else if (topLevelInDesigner)
                             {
                                 attributes.Add(new Triplet(filter, str2, null));
                             }
                         }
                         else if (topLevelInDesigner)
                         {
                             attributes.Add(new Triplet(filter, str2, null));
                         }
                         if (persistData != null)
                         {
                             foreach (PropertyEntry entry2 in persistData.GetPropertyAllFilters(str3))
                             {
                                 if (string.Compare(entry2.Filter, filter, StringComparison.OrdinalIgnoreCase) != 0)
                                 {
                                     string str5 = string.Empty;
                                     if (entry2 is SimplePropertyEntry)
                                     {
                                         SimplePropertyEntry entry3 = (SimplePropertyEntry) entry2;
                                         if (entry3.UseSetAttribute)
                                         {
                                             str5 = entry3.Value.ToString();
                                         }
                                         else
                                         {
                                             str5 = GetPersistValue(propDesc, entry2.Type, entry3.Value, BindingType.None, topLevelInDesigner);
                                         }
                                     }
                                     else if (entry2 is BoundPropertyEntry)
                                     {
                                         BoundPropertyEntry entry4 = (BoundPropertyEntry) entry2;
                                         if (entry4.Generated)
                                         {
                                             continue;
                                         }
                                         string propValue = entry4.Expression.Trim();
                                         none = BindingType.Data;
                                         string expressionPrefix = entry4.ExpressionPrefix;
                                         if (expressionPrefix.Length > 0)
                                         {
                                             propValue = expressionPrefix + ":" + propValue;
                                             none = BindingType.Expression;
                                         }
                                         str5 = GetPersistValue(propDesc, entry2.Type, propValue, none, topLevelInDesigner);
                                     }
                                     else if (entry2 is ComplexPropertyEntry)
                                     {
                                         ComplexPropertyEntry entry5 = (ComplexPropertyEntry) entry2;
                                         str5 = (string) entry5.Builder.BuildObject();
                                     }
                                     attributes.Add(new Triplet(entry2.Filter, str2, str5));
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }
 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);
     }
 }
示例#13
0
        /*
         * 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()));
 }