示例#1
0
        internal static string[] getDefaultViewPropChain(object view, string[] vmPropChain)
        {
            var vmPropertyName = vmPropChain.Last();
            var getter         = GetValueFetcherForProperty(view.GetType(), vmPropertyName);

            if (getter == null)
            {
                throw new Exception(String.Format("Tried to bind to control but it wasn't present on the object: {0}.{1}",
                                                  view.GetType().FullName, vmPropertyName));
            }

            var control = getter(view);

            if (control == null)
            {
                throw new Exception(String.Format("Tried to bind to control but it was null: {0}.{1}", view.GetType().FullName,
                                                  vmPropertyName));
            }

            var defaultProperty = DefaultPropertyBinding.GetPropertyForControl(control);

            if (defaultProperty == null)
            {
                throw new Exception(String.Format("Couldn't find a default property for type {0}", control.GetType()));
            }
            return(new[] { vmPropertyName, defaultProperty });
        }
示例#2
0
        internal static Expression getViewExpressionWithProperty(object view, Expression vmExpression)
        {
            var controlExpression = getViewExpression(view, vmExpression);

            var control = GetValueFetcherForProperty(controlExpression.GetMemberInfo())(view, controlExpression.GetArgumentsArray());

            if (control == null)
            {
                throw new Exception(String.Format("Tried to bind to control but it was null: {0}.{1}", view.GetType().FullName,
                                                  controlExpression.GetMemberInfo().Name));
            }

            var defaultProperty = DefaultPropertyBinding.GetPropertyForControl(control);

            if (defaultProperty == null)
            {
                throw new Exception(String.Format("Couldn't find a default property for type {0}", control.GetType()));
            }
            return(Expression.MakeMemberAccess(controlExpression, control.GetType().GetRuntimeProperty(defaultProperty)));
        }