示例#1
0
        public void Create_Should_Create_Seperate_Factory_Instances()
        {
            var factoryFactory = new FactoryFactory <StringBuilder>();
            var factory1       = factoryFactory.Create();
            var factory2       = factoryFactory.Create();

            var stringBuilder1 = factory1.Create();
            var stringBuilder2 = factory1.Create();

            Assert.IsFalse(ReferenceEquals(factory1, factory2));
            Assert.IsFalse(ReferenceEquals(stringBuilder1, stringBuilder2));
        }
示例#2
0
        public void Create_Should_Create_NullFactory_Factory()
        {
            var nullFactoryFactoryFactory = new FactoryFactory <NullFactory>();
            var nullFactoryFactory        = nullFactoryFactoryFactory.Create();
            var nullFactory = nullFactoryFactory.Create();

            Assert.AreEqual(typeof(NullFactory), nullFactory.GetType());
        }
示例#3
0
        public void Create_Should_Create_Int_Factory()
        {
            var factoryFactory = new FactoryFactory <int>();
            var factory        = factoryFactory.Create();
            var value          = factory.Create();

            Assert.AreEqual(typeof(Factory <int>), factory.GetType());
            Assert.AreEqual(0, value);
        }
示例#4
0
        public void Create_Should_Create_Different_Value_Objects()
        {
            var factoryFactory = new FactoryFactory <int>();
            var factory        = factoryFactory.Create();

            var int1 = factory.Create();
            var int2 = factory.Create();

            Assert.IsFalse(ReferenceEquals(int1, int2));
        }
示例#5
0
        // We can't call this.  See: https://bugzilla.xamarin.com/show_bug.cgi?id=30843
        //public override View Inflate(XmlReader parser, ViewGroup root, bool attachToRoot)
        //{
        //    SetPrivateFactoryInternal();
        //    return base.Inflate(parser, root, attachToRoot);
        //}

        // Calligraphy doesn't override this one...
        public override View Inflate(int resource, ViewGroup root, bool attachToRoot)
        {
            // Make sure our private factory is set since LayoutInflater > Honeycomb
            // uses a private factory.
            SetPrivateFactoryInternal();

            // Save the old factory in case we are recursing because of an MvxAdapter etc.
            IMvxLayoutInflaterHolderFactory originalFactory = _bindingVisitor.Factory;

            try
            {
                IMvxLayoutInflaterHolderFactory factory = null;

                // Get the current binding context
                var currentBindingContext = MvxAndroidBindingContextHelpers.Current();
                if (currentBindingContext != null)
                {
                    factory = FactoryFactory?.Create(currentBindingContext.DataContext);

                    // Set the current factory used to generate bindings
                    if (factory != null)
                    {
                        _bindingVisitor.Factory = factory;
                    }
                }

                // Inflate the resource
                var view = base.Inflate(resource, root, attachToRoot);

                // Register bindings with clear key
                if (currentBindingContext != null)
                {
                    if (factory != null)
                    {
                        currentBindingContext.RegisterBindingsWithClearKey(view, factory.CreatedBindings);
                    }
                }

                return(view);
            }
            finally
            {
                _bindingVisitor.Factory = originalFactory;
            }
        }