Esempio n. 1
0
        /// <summary>
        /// Sets the binding properties.
        /// </summary>
        private void SetBindingProperties(MarkupExpression binding, List<Expressions.BindingPathExpression> parameters)
        {
            var type = binding.GetType();
            foreach (var parameter in parameters.OfType<BindingParameterSetExpression>())
            {
                // get property
                var prop = type.GetProperty(parameter.ParameterName);
                if (prop == null)
                {
                    ThrowParserError(string.Format("The markup extension '{0}' does not have a property '{1}'!", binding.MarkupExtensionName, parameter.ParameterName));
                }

                // set value
                if (prop.PropertyType == typeof (Expressions.BindingPathExpression))
                {
                    // value is expression
                    prop.SetValue(binding, parameter.Value);
                }
                else
                {
                    // value is constant
                    var converter = TypeConverterMapper.Default.GetConverterForType(prop.PropertyType);
                    object value;
                    if (!converter.TryConvertFromString(ConvertExpressionToConstant(parameter.Value, parameter.ParameterName), out value))
                    {
                        ThrowParserError(string.Format("The value assigned to property '{0}' could not be converted to type '{1}'!", parameter.ParameterName, prop.PropertyType.FullName));
                    }
                    prop.SetValue(binding, value);
                }
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Gets the binding default property.
 /// </summary>
 private string GetBindingDefaultProperty(MarkupExpression binding)
 {
     var attr = binding.GetType().GetCustomAttribute<DefaultPropertyAttribute>();
     if (attr == null) return string.Empty;
     return attr.Name;
 }