コード例 #1
0
            /// <summary>
            /// Gets the property that implements the compiled version of the specified binding expression.
            /// </summary>
            /// <param name="type">The type of the expression for which to retrieve an implementing property.</param>
            /// <param name="expression">The text of the expression for which to retrieve an implementing property.</param>
            /// <returns>A <see cref="PropertyInfo"/> which represents the property that implements the compiled version of the specified binding expression,
            /// or <c>null</c> if the expression has no compiled equivalent.</returns>
            public PropertyInfo GetCompiledBindingExpression(Type type, String expression)
            {
                PropertyInfo property;

                var key = new CompiledBindingExpressionKey(type, expression);
                if (compiledBindingExpressions.TryGetValue(key, out property))
                    return property;

                return null;
            }
コード例 #2
0
        /// <summary>
        /// Finds all of the compiled binding expressions on the current data
        /// source and adds them to the context's registry.
        /// </summary>
        private void FindCompiledBindingExpressions()
        {
            var wrapperName = default(String);
            var wrapperType = DataSource is PresentationFoundationView ? DataSourceType : null;

            if (wrapperType == null)
            {
                for (var templateType = TemplatedParent.GetType(); templateType != null; templateType = templateType.BaseType)
                {
                    wrapperName = PresentationFoundationView.GetDataSourceWrapperNameForComponentTemplate(templateType);
                    wrapperType = Ultraviolet.GetUI().GetPresentationFoundation().GetDataSourceWrapperTypeByName(wrapperName);

                    if (wrapperType != null)
                    {
                        break;
                    }
                }

                if (wrapperType == null)
                {
                    wrapperName = PresentationFoundationView.GetDataSourceWrapperNameForComponentTemplate(TemplatedParent.GetType());
                    throw new UvmlException(PresentationStrings.CannotFindViewModelWrapper.Format(wrapperName));
                }
            }

            var properties = wrapperType.GetProperties().Where(x => x.Name.StartsWith("__UPF_Expression")).ToList();
            var propertiesWithExpressions = from prop in properties
                                            let attr                       = (CompiledBindingExpressionAttribute)prop.GetCustomAttributes(typeof(CompiledBindingExpressionAttribute), false).Single()
                                                                  let expr = attr.Expression
                                                                             select new
            {
                Property   = prop,
                Expression = expr,
            };

            foreach (var prop in propertiesWithExpressions)
            {
                var key = new CompiledBindingExpressionKey(prop.Property.PropertyType, prop.Expression);
                compiledBindingExpressions.Add(key, prop.Property);
            }

            var uniques = compiledBindingExpressions.GroupBy(x => x.Key).Where(x => x.Count() == 1).ToList();

            foreach (var unique in uniques)
            {
                var key = new CompiledBindingExpressionKey(null, unique.Key.Expression);
                compiledBindingExpressions[key] = unique.Single().Value;
            }
        }
コード例 #3
0
        /// <summary>
        /// Gets the property that implements specified compiled binding expression, if it exists in the current context.
        /// </summary>
        /// <param name="type">The type of the expression for which to retrieve an implementing property.</param>
        /// <param name="expression">The text of the expression for which to retrieve an implementing property.</param>
        /// <returns>A <see cref="PropertyInfo"/> which represents the property that implements the compiled version of the
        /// specified binding expression, or <see langword="null"/> if the expression has no compiled equivalent.</returns>
        public PropertyInfo GetCompiledBindingExpression(Type type, String expression)
        {
            PropertyInfo property;

            var specificKey = new CompiledBindingExpressionKey(type, expression);

            if (compiledBindingExpressions.TryGetValue(specificKey, out property))
            {
                return(property);
            }

            var fallbackKey = new CompiledBindingExpressionKey(null, expression);

            if (compiledBindingExpressions.TryGetValue(fallbackKey, out property))
            {
                return(property);
            }

            return(null);
        }
コード例 #4
0
            /// <summary>
            /// Finds all of the compiled binding expressions on the current view model and adds them to the context's registry.
            /// </summary>
            private void FindCompiledBindingExpressions()
            {
                var wrapperName = default(String);
                var wrapperType = DataSource is PresentationFoundationView ? DataSourceType : null;
                if (wrapperType == null)
                {
                    for (var templateType = TemplatedParent.GetType(); templateType != null; templateType = templateType.BaseType)
                    {
                        wrapperName = PresentationFoundationView.GetDataSourceWrapperNameForComponentTemplate(templateType);
                        wrapperType = Ultraviolet.GetUI().GetPresentationFoundation().GetDataSourceWrapperTypeByName(wrapperName);

                        if (wrapperType != null)
                            break;
                    }

                    if (wrapperType == null)
                        throw new InvalidOperationException(PresentationStrings.CannotFindViewModelWrapper.Format(wrapperName));
                }

                var properties = wrapperType.GetProperties().Where(x => x.Name.StartsWith("__UPF_Expression")).ToList();
                var propertiesWithExpressions = from prop in properties
                                                let attr = (CompiledBindingExpressionAttribute)prop.GetCustomAttributes(typeof(CompiledBindingExpressionAttribute), false).Single()
                                                let expr = attr.Expression
                                                select new
                                                {
                                                    Property = prop,
                                                    Expression = expr,
                                                };

                foreach (var prop in propertiesWithExpressions)
                {
                    var key = new CompiledBindingExpressionKey(prop.Property.PropertyType, prop.Expression);
                    compiledBindingExpressions.Add(key, prop.Property);
                }
            }
コード例 #5
0
        /// <summary>
        /// Gets the property that implements specified compiled binding expression, if it exists in the current context.
        /// </summary>
        /// <param name="type">The type of the expression for which to retrieve an implementing property.</param>
        /// <param name="expression">The text of the expression for which to retrieve an implementing property.</param>
        /// <returns>A <see cref="PropertyInfo"/> which represents the property that implements the compiled version of the 
        /// specified binding expression, or <see langword="null"/> if the expression has no compiled equivalent.</returns>
        public PropertyInfo GetCompiledBindingExpression(Type type, String expression)
        {
            PropertyInfo property;

            var specificKey = new CompiledBindingExpressionKey(type, expression);
            if (compiledBindingExpressions.TryGetValue(specificKey, out property))
                return property;

            var fallbackKey = new CompiledBindingExpressionKey(null, expression);
            if (compiledBindingExpressions.TryGetValue(fallbackKey, out property))
                return property;

            return null;
        }