public override ITypeDescriptor GetChildDataContextType(ITypeDescriptor dataContext, IDataContextStack controlContextStack, IAbstractControl control, IPropertyDescriptor property = null)
        {
            IPropertyDescriptor controlProperty;

            if (!control.Metadata.TryGetProperty(PropertyName, out controlProperty))
            {
                throw new Exception($"The property '{PropertyName}' was not found on control '{control.Metadata.Type}'!");
            }

            IAbstractPropertySetter setter;

            if (control.TryGetProperty(controlProperty, out setter))
            {
                var binding = setter as IAbstractPropertyBinding;
                if (binding == null)
                {
                    return(dataContext);
                }
                return(binding.Binding.ResultType);
            }
            else
            {
                if (AllowMissingProperty)
                {
                    return(dataContext);
                }
                else
                {
                    throw new Exception($"Property '{PropertyName}' is required on '{control.Metadata.Type.Name}'.");
                }
            }
        }
        public static IAbstractPropertySetter GetPropertyGroupMember(this IAbstractControl control, string prefix, string memberName)
        {
            IAbstractPropertySetter value;

            control.TryGetProperty(control.Metadata.GetPropertyGroupMember(prefix, memberName), out value);
            return(value);
        }
        public override ITypeDescriptor GetChildDataContextType(ITypeDescriptor dataContext, IDataContextStack controlContextStack, IAbstractControl control, IPropertyDescriptor property = null)
        {
            if (!control.Metadata.TryGetProperty(PropertyName, out var controlProperty))
            {
                throw new Exception($"The property '{PropertyName}' was not found on control '{control.Metadata.Type}'!");
            }

            if (control.TryGetProperty(controlProperty, out var setter) && setter is IAbstractPropertyBinding binding)
            {
                return(binding.Binding.ResultType);
            }

            return(controlProperty.PropertyType);
        }
Exemple #4
0
        /// <summary>
        /// Gets the data context change behavior for the specified control property.
        /// </summary>
        protected virtual IDataContextStack GetDataContextChange(IDataContextStack dataContext, IAbstractControl control, IPropertyDescriptor property)
        {
            if (dataContext == null)
            {
                return(null);
            }

            var manipulationAttribute = property != null ? property.DataContextManipulationAttribute : control.Metadata.DataContextManipulationAttribute;

            if (manipulationAttribute != null)
            {
                return(manipulationAttribute.ChangeStackForChildren(dataContext, control, property, (parent, changeType) => CreateDataContextTypeStack(changeType, parentDataContextStack: parent)));
            }

            var attributes = property != null ? property.DataContextChangeAttributes : control.Metadata.DataContextChangeAttributes;

            if (attributes == null || attributes.Length == 0)
            {
                return(dataContext);
            }

            try
            {
                var(type, extensionParameters) = ApplyContextChange(dataContext, attributes, control, property);

                if (type == null)
                {
                    return(dataContext);
                }
                else
                {
                    return(CreateDataContextTypeStack(type, parentDataContextStack: dataContext, extensionParameters: extensionParameters.ToArray()));
                }
            }
            catch (Exception exception)
            {
                var node = property != null && control.TryGetProperty(property, out var v) ? v.DothtmlNode : control.DothtmlNode;
                node?.AddError($"Could not compute the type of DataContext: {exception}");

                return(CreateDataContextTypeStack(null, parentDataContextStack: dataContext));
            }
        }
        public override ITypeDescriptor?GetChildDataContextType(ITypeDescriptor dataContext, IDataContextStack controlContextStack, IAbstractControl control, IPropertyDescriptor?property = null)
        {
            if (!control.Metadata.TryGetProperty(PropertyName, out var controlProperty))
            {
                throw new Exception($"The property '{PropertyName}' was not found on control '{control.Metadata.Type}'!");
            }

            if (control.TryGetProperty(controlProperty, out var setter))
            {
                return(setter is IAbstractPropertyBinding binding
                    ? binding.Binding.ResultType ?? throw new Exception($"The '{controlProperty.Name}' property contains invalid data-binding")
                    : dataContext);
            }

            if (AllowMissingProperty)
            {
                return(dataContext);
            }

            throw new Exception($"Property '{PropertyName}' is required on '{control.Metadata.Type.Name}'.");
        }
        public override ITypeDescriptor GetChildDataContextType(ITypeDescriptor dataContext, IDataContextStack controlContextStack, IAbstractControl control, IPropertyDescriptor property = null)
        {
            IPropertyDescriptor controlProperty;
            if (!control.Metadata.TryGetProperty(PropertyName, out controlProperty))
            {
                throw new Exception($"The property '{PropertyName}' was not found on control '{control.Metadata.Type}'!");
            }

            IAbstractPropertySetter setter;
            if (control.TryGetProperty(controlProperty, out setter))
            {
                var binding = setter as IAbstractPropertyBinding;
                if (binding == null)
                {
                    return dataContext;
                }
                return binding.Binding.ResultType;
            }
            else
            {
                if (AllowMissingProperty) return dataContext;
                else throw new Exception($"Property '{PropertyName}' is required on '{control.Metadata.Type.Name}'.");
            }
        }
        public static bool HasPropertyValue(this IAbstractControl control, IPropertyDescriptor property)
        {
            IAbstractPropertySetter setter;

            return(control.TryGetProperty(property, out setter) && setter is IAbstractPropertyValue);
        }
        => control.Content.All(c => !DothtmlNodeHelper.IsNotEmpty(c.DothtmlNode));     // allow only whitespace literals

        public static bool HasProperty(this IAbstractControl control, IPropertyDescriptor property)
        {
            IAbstractPropertySetter blackHole;

            return(control.TryGetProperty(property, out blackHole));
        }