Esempio n. 1
0
        internal static void PerformExtensionDelegates(HtmlObject control)
        {
            if (!_extensionDelegatesMap.ContainsKey(control.GetType()))
            {
                return;
            }
            var delegates = _extensionDelegatesMap[control.GetType()];

            foreach (var delegateItem in delegates)
            {
                delegateItem.Invoke(control);
            }
        }
Esempio n. 2
0
        internal void Resolve(HtmlObject instance, ControlProperty targetProperty)
        {
            Object value = null;

            if (ValueProvider != null)
            {
                value = ValueProvider.GetValue(instance.DataItem);
            }
            else if (_pathParts != null || _resolvePending)
            {
                if (_resolvePending)
                {
                    CompilePropertyPath();
                }
                var data = instance.DataItem;
                for (var i = 0; i < _pathParts.Length; i++)
                {
                    var key = _pathParts[i];
                    try
                    {
                        switch (_resolveMethods[i])
                        {
                        case ResolveMethod.PropertyValue:
                            data = ReflectionHelper.ReadProperty(data, key); break;

                        case ResolveMethod.ViewDataEntry:
                            data = instance.CurrentContext[key]; break;

                        case ResolveMethod.MethodCall:
                            data = ReflectionHelper.InvokeInstanceMethod(data, key); break;

                        case ResolveMethod.CurrentDataItem:
                            data = instance.DataItem; break;

                        case ResolveMethod.VisualTreeObject:
                            throw new NotImplementedException();
                        }
                        if (data == null)
                        {
                            break;
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new BindingException(String.Format("Error on resolve property path {0} to property {1}.{2}", PropertyPath, instance.GetType().Name, targetProperty.Name), ex);
                    }
                }
                value = data;
            }
            else
            {
                value = instance.DataItem;
            }

            if (Formatter != null)
            {
                value = Formatter.Format(value);
                if (Formatter.Align != TextAlignment.Default)
                {
                    instance.SetValue(HtmlControl.TextAlignProperty, Formatter.Align);
                }
            }
            if (!String.IsNullOrEmpty(FormatString))
            {
                value = String.Format(FormatString, value);
            }

            instance.SetValue(targetProperty, value);
        }