Mono.Xaml.XamlReflectionPropertySetter.SetValue C# (CSharp) Method

SetValue() public method

public SetValue ( XamlObjectElement obj, object value ) : void
obj XamlObjectElement
value object
return void
		public override void SetValue (XamlObjectElement obj, object value)
		{
			// We do this first to cover the case where you are setting a list to a list or
			// a resource dictionary to a resource dictionary, binding to a binding, ect
			// as opposed to adding items to the list or dictionary.
			if (Type.IsAssignableFrom (value.GetType ())) {
				prop.SetValue (target, ConvertValue (Type, value), null);
				return;
			}

			{
				Binding binding = value as Binding;
				if (binding != null) {
					SetBinding (binding);
					return;
				}
			}

			{
				TemplateBindingExpression tb = value as TemplateBindingExpression;
				if (tb != null) {
					SetTemplateBinding (tb);
					return;
				}
			}

			if (typeof (IList).IsAssignableFrom (Type)) {
				AddToCollection (obj, value);
				return;
			}

			if (typeof (IDictionary).IsAssignableFrom (Type)) {
				AddToDictionary (obj, value);
				return;
			}

			throw Parser.ParseException ("Unable to set property {0} to value {1}.", Name, value);
		}

Usage Example

Ejemplo n.º 1
0
        private void AddChildObject(XamlObjectElement obj)
        {
            object        value   = obj.Object;
            MutableObject mutable = value as MutableObject;

            if (mutable != null)
            {
                value = mutable.Object;
            }

            IList list = Object as IList;

            if (list != null)
            {
                list.Add(value);
                return;
            }

            IDictionary dict = Object as IDictionary;

            if (dict != null)
            {
                dict.Add(obj.GetDictionaryKey(), value);
                return;
            }

            XamlReflectionPropertySetter content_property = FindContentProperty();

            if (content_property == null)
            {
                throw Parser.ParseException("Unable to add element {0} to element {1}.", obj.Name, Name);
            }

            content_property.SetValue(value);
        }