Beispiel #1
0
        private static IEnumerable <IView> GetViewsToBind(
            PresenterBindingAttribute attribute,
            IView view,
            IEnumerable <IView> pendingViews)
        {
            Debug.Assert(attribute != null);
            Debug.Assert(view != null);
            Debug.Assert(pendingViews != null);

            Trace.TraceInformation(
                "[AttributeBasedPresenterDiscoveryStrategy] Found presenter '{0}' for view '{1}', origin='{2}', binding mode='{3}'.",
                attribute.PresenterType.FullName,
                attribute.ViewType?.FullName,
                attribute.Origin?.FullName,
                attribute.BindingMode.ToString());

            switch (attribute.BindingMode)
            {
            case PresenterBindingMode.Default:
                return(new[] { view });

            case PresenterBindingMode.SharedPresenter:
                return(pendingViews.Where(_ => attribute.ViewType?.IsInstanceOfType(_) ?? false));

            default:
                throw new ControlFlowException();
            }
        }
        static IEnumerable<IView> GetViewInstancesToBind(IEnumerable<IView> pendingViewInstances, IView viewInstance, Type viewType, ICollection<string> messages, PresenterBindingAttribute attribute)
        {
            IEnumerable<IView> viewInstancesToBind;
            switch (attribute.BindingMode)
            {
                case BindingMode.Default:
                    viewInstancesToBind = new[] {viewInstance};
                    break;
                case BindingMode.SharedPresenter:
                    viewInstancesToBind = pendingViewInstances
                        .Where(v => attribute.ViewType.IsAssignableFrom(viewType))
                        .ToArray();

                    messages.Add(string.Format(
                        CultureInfo.InvariantCulture,
                        "including {0} more view instances in the binding because the binding mode is {1} and they are compatible with the view type {2}",
                        viewInstancesToBind.Count() - 1,
                        attribute.BindingMode,
                        attribute.ViewType.FullName
                    ));

                    break;
                default:
                    throw new NotSupportedException(string.Format(CultureInfo.InvariantCulture, "Binding mode {0} is not supported", attribute.BindingMode));
            }
            return viewInstancesToBind;
        }
Beispiel #3
0
        internal static IEnumerable <IView> GetViewInstancesToBind(IEnumerable <IView> pendingViewInstances, IView viewInstance, Type viewType, ICollection <string> messages, PresenterBindingAttribute attribute)
        {
            IEnumerable <IView> viewInstancesToBind;

            switch (attribute.BindingMode)
            {
            case BindingMode.Default:
                viewInstancesToBind = new[] { viewInstance };
                break;

            case BindingMode.SharedPresenter:
                viewInstancesToBind = pendingViewInstances
                                      .Where(viewType.IsInstanceOfType)
                                      .ToArray();

                messages.Add(string.Format(
                                 CultureInfo.InvariantCulture,
                                 "including {0} more view instances in the binding because the binding mode is {1} and they are compatible with the view type {2}",
                                 viewInstancesToBind.Count() - 1,
                                 attribute.BindingMode,
                                 attribute.ViewType.FullName
                                 ));

                break;

            default:
                throw new NotSupportedException(string.Format(CultureInfo.InvariantCulture, "Binding mode {0} is not supported", attribute.BindingMode));
            }
            return(viewInstancesToBind);
        }
        public void PresenterBindingAttribute_Ctor_SetsBindingModeToDefault()
        {
            var attribute = new PresenterBindingAttribute(typeof(TestPresenter));

            Assert.AreEqual(BindingMode.Default, attribute.BindingMode);
        }
        public void PresenterBindingAttribute_Ctor_SetsViewTypeToNull()
        {
            var attribute = new PresenterBindingAttribute(typeof(TestPresenter));

            Assert.IsNull(attribute.ViewType);
        }
        public void PresenterBindingAttribute_Ctor_SetsPresenterType()
        {
            var attribute = new PresenterBindingAttribute(typeof(TestPresenter));

            Assert.AreEqual(typeof(TestPresenter), attribute.PresenterType);
        }