Exemple #1
0
        public override Type GetChildDataContextType(Type dataContext, DataContextStack controlContextStack, DotvvmBindableObject control, DotvvmProperty property = null)
        {
            var controlType          = control.GetType();
            var controlPropertyField = controlType.GetField($"{PropertyName}Property", BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy);
            var controlProperty      = (DotvvmProperty)controlPropertyField?.GetValue(null);

            if (controlProperty == null)
            {
                throw new Exception($"The property '{PropertyName}' was not found on control '{controlType}'!");
            }

            if (control.Properties.ContainsKey(controlProperty))
            {
                return(control.HasValueBinding(controlProperty)
                    ? control.GetValueBinding(controlProperty).ResultType
                    : dataContext);
            }

            if (AllowMissingProperty)
            {
                return(dataContext);
            }

            throw new Exception($"Property '{PropertyName}' is required on '{controlType.Name}'.");
        }