コード例 #1
0
        public static void CallBundleMethod(this IMvxViewModel viewModel, MethodInfo methodInfo, IMvxBundle bundle)
        {
            var parameters = methodInfo.GetParameters().ToArray();

            if (parameters.Count() == 1 &&
                parameters[0].ParameterType == typeof(IMvxBundle))
            {
                // this method is the 'normal' interface method
                methodInfo.Invoke(viewModel, new object[] { bundle });
                return;
            }

            if (parameters.Count() == 1 &&
                !MvxStringToTypeParser.TypeSupported(parameters[0].ParameterType))
            {
                // call method using typed object
                var value = bundle.Read(parameters[0].ParameterType);
                methodInfo.Invoke(viewModel, new[] { value });
                return;
            }

            // call method using named method arguments
            var invokeWith = bundle.CreateArgumentList(parameters, viewModel.GetType().Name)
                             .ToArray();

            methodInfo.Invoke(viewModel, invokeWith);
        }
コード例 #2
0
 public void Test_AllTypesAreSupported()
 {
     Assert.IsTrue(MvxStringToTypeParser.TypeSupported(typeof(string)));
     Assert.IsTrue(MvxStringToTypeParser.TypeSupported(typeof(int)));
     Assert.IsTrue(MvxStringToTypeParser.TypeSupported(typeof(long)));
     Assert.IsTrue(MvxStringToTypeParser.TypeSupported(typeof(double)));
     Assert.IsTrue(MvxStringToTypeParser.TypeSupported(typeof(bool)));
     Assert.IsTrue(MvxStringToTypeParser.TypeSupported(typeof(Guid)));
     Assert.IsTrue(MvxStringToTypeParser.TypeSupported(typeof(StringSplitOptions)));
 }
コード例 #3
0
        public void IncludeMvvmcross64()
        {
            _ = new MvxSettings();
            _ = new MvxStringToTypeParser(); //??
            //_ = new MvxPluginManager(null); //should not be required
            _ = new MvxViewModelLoader(null);
            _ = new MvxNavigationService(null, null);
            _ = new MvxViewModelByNameLookup();

            _ = new MvxViewModelViewTypeFinder(null, null);
            _ = new MvxViewModelViewLookupBuilder();
            _ = new MvxCommandCollectionBuilder();
            _ = new MvxStringDictionaryNavigationSerializer();
            _ = new MvxChildViewModelCache();
            _ = new MvxWeakCommandHelper();
        }
コード例 #4
0
        public void Test_AllTypesAreSupported()
        {
            var parser = new MvxStringToTypeParser();

            Assert.IsTrue(parser.TypeSupported(typeof(string)));
            Assert.IsTrue(parser.TypeSupported(typeof(int)));
            Assert.IsTrue(parser.TypeSupported(typeof(long)));
            Assert.IsTrue(parser.TypeSupported(typeof(short)));
            Assert.IsTrue(parser.TypeSupported(typeof(float)));
            Assert.IsTrue(parser.TypeSupported(typeof(uint)));
            Assert.IsTrue(parser.TypeSupported(typeof(ulong)));
            Assert.IsTrue(parser.TypeSupported(typeof(ushort)));
            Assert.IsTrue(parser.TypeSupported(typeof(double)));
            Assert.IsTrue(parser.TypeSupported(typeof(bool)));
            Assert.IsTrue(parser.TypeSupported(typeof(Guid)));
            Assert.IsTrue(parser.TypeSupported(typeof(StringSplitOptions)));
        }
コード例 #5
0
 public void Include(MvxStringToTypeParser parser)
 {
     _ = new MvxStringToTypeParser();
 }
コード例 #6
0
        public void Test_AllTypesCanBeRead()
        {
            var parser = new MvxStringToTypeParser();

            Assert.AreEqual("Hello World", parser.ReadValue("Hello World", typeof(string), "ignored"));
            Assert.AreEqual("", parser.ReadValue("", typeof(string), "ignored"));
            Assert.AreEqual(null, parser.ReadValue(null, typeof(string), "ignored"));

            Assert.AreEqual(1.23, parser.ReadValue("1.23", typeof(double), "ignored"));
            Assert.AreEqual(123.0, parser.ReadValue("1,23", typeof(double), "ignored"),
                            "comma separators ignored under invariant parsing");
            Assert.AreEqual(0, parser.ReadValue("garbage", typeof(double), "ignored"));
            Assert.AreEqual(0, parser.ReadValue("", typeof(double), "ignored"));
            Assert.AreEqual(0, parser.ReadValue(null, typeof(double), "ignored"));

            Assert.AreEqual(1.23f, parser.ReadValue("1.23", typeof(float), "ignored"));
            Assert.AreEqual(123.0f, parser.ReadValue("1,23", typeof(float), "ignored"),
                            "comma separators ignored under invariant parsing");
            Assert.AreEqual(0f, parser.ReadValue("garbage", typeof(float), "ignored"));
            Assert.AreEqual(0f, parser.ReadValue("", typeof(float), "ignored"));
            Assert.AreEqual(0f, parser.ReadValue(null, typeof(float), "ignored"));

            Assert.AreEqual(123, parser.ReadValue("123", typeof(int), "ignored"));
            Assert.AreEqual(0, parser.ReadValue("12.3", typeof(int), "ignored"),
                            "partial integers should not be parsed");
            Assert.AreEqual(0, parser.ReadValue("garbage", typeof(int), "ignored"));
            Assert.AreEqual(0, parser.ReadValue("", typeof(int), "ignored"));
            Assert.AreEqual(0, parser.ReadValue(null, typeof(int), "ignored"));

            Assert.AreEqual(123L, parser.ReadValue("123", typeof(long), "ignored"));
            Assert.AreEqual(0, parser.ReadValue("12.3", typeof(long), "ignored"),
                            "partial integers should not be parsed");
            Assert.AreEqual(0L, parser.ReadValue("garbage", typeof(long), "ignored"));
            Assert.AreEqual(0L, parser.ReadValue("", typeof(long), "ignored"));
            Assert.AreEqual(0L, parser.ReadValue(null, typeof(long), "ignored"));

            Assert.AreEqual((ulong)123L, parser.ReadValue("123", typeof(ulong), "ignored"));
            Assert.AreEqual((ulong)0, parser.ReadValue("12.3", typeof(ulong), "ignored"),
                            "partial integers should not be parsed");
            Assert.AreEqual((ulong)0L, parser.ReadValue("garbage", typeof(ulong), "ignored"));
            Assert.AreEqual((ulong)0L, parser.ReadValue("", typeof(ulong), "ignored"));
            Assert.AreEqual((ulong)0L, parser.ReadValue(null, typeof(ulong), "ignored"));

            Assert.AreEqual((ushort)123, parser.ReadValue("123", typeof(ushort), "ignored"));
            Assert.AreEqual((ushort)0, parser.ReadValue("12.3", typeof(ushort), "ignored"),
                            "partial integers should not be parsed");
            Assert.AreEqual((ushort)0, parser.ReadValue("garbage", typeof(ushort), "ignored"));
            Assert.AreEqual((ushort)0, parser.ReadValue("", typeof(ushort), "ignored"));
            Assert.AreEqual((ushort)0, parser.ReadValue(null, typeof(ushort), "ignored"));

            Assert.AreEqual(true, parser.ReadValue("true", typeof(bool), "ignored"));
            Assert.AreEqual(true, parser.ReadValue("True", typeof(bool), "ignored"));
            Assert.AreEqual(true, parser.ReadValue("TRUE", typeof(bool), "ignored"));
            Assert.AreEqual(true, parser.ReadValue("truE", typeof(bool), "ignored"));
            Assert.AreEqual(false, parser.ReadValue("false", typeof(bool), "ignored"));
            Assert.AreEqual(false, parser.ReadValue("False", typeof(bool), "ignored"));
            Assert.AreEqual(false, parser.ReadValue("FALSE", typeof(bool), "ignored"));
            Assert.AreEqual(false, parser.ReadValue("falsE", typeof(bool), "ignored"));
            Assert.AreEqual(false, parser.ReadValue("garbage", typeof(bool), "ignored"));
            Assert.AreEqual(false, parser.ReadValue("", typeof(bool), "ignored"));
            Assert.AreEqual(false, parser.ReadValue(null, typeof(bool), "ignored"));

            var guid = Guid.Parse("{C3CF9078-0122-41BD-9E2D-D3199E937285}");

            Assert.AreEqual(guid,
                            parser.ReadValue("{C3CF9078-0122-41BD-9E2D-D3199E937285}", typeof(Guid),
                                             "ignored"));
            Assert.AreEqual(guid,
                            parser.ReadValue(
                                "{C3CF9078-0122-41BD-9E2D-D3199E937285}".ToLowerInvariant(), typeof(Guid), "ignored"));
            Assert.AreEqual(Guid.Empty,
                            parser.ReadValue("{F9078-0122-41BD-9E2D-D3199E93}", typeof(Guid), "ignored"));
            Assert.AreEqual(Guid.Empty, parser.ReadValue("garbage", typeof(Guid), "ignored"));
            Assert.AreEqual(Guid.Empty, parser.ReadValue("", typeof(Guid), "ignored"));
            Assert.AreEqual(Guid.Empty, parser.ReadValue(null, typeof(Guid), "ignored"));

            Assert.AreEqual(StringSplitOptions.RemoveEmptyEntries,
                            parser.ReadValue("RemoveEmptyEntries", typeof(StringSplitOptions), "ignored"));
            Assert.AreEqual(StringSplitOptions.None,
                            parser.ReadValue("None".ToLowerInvariant(), typeof(StringSplitOptions),
                                             "ignored"));
            Assert.AreEqual(StringSplitOptions.None,
                            parser.ReadValue("garbage", typeof(StringSplitOptions), "ignored"));
            Assert.AreEqual(StringSplitOptions.None,
                            parser.ReadValue("", typeof(StringSplitOptions), "ignored"));
            Assert.AreEqual(StringSplitOptions.None,
                            parser.ReadValue(null, typeof(StringSplitOptions), "ignored"));
        }
コード例 #7
0
        public void Test_IntCanBeRead(string testData, int expected)
        {
            var parser = new MvxStringToTypeParser();

            Assert.Equal(expected, parser.ReadValue(testData, typeof(int), "ignored"));
        }
コード例 #8
0
        public void Test_StringCanBeRead(string testData)
        {
            var parser = new MvxStringToTypeParser();

            Assert.Equal(testData, parser.ReadValue(testData, typeof(string), "ignored"));
        }
コード例 #9
0
        public void Test_EnumTypeCanBeRead(string testData, StringSplitOptions expected)
        {
            var parser = new MvxStringToTypeParser();

            Assert.Equal(expected, parser.ReadValue(testData, typeof(StringSplitOptions), "ignored"));
        }
コード例 #10
0
        public void Test_ULongCanBeRead(string testData, ulong expected)
        {
            var parser = new MvxStringToTypeParser();

            Assert.Equal(expected, parser.ReadValue(testData, typeof(ulong), "ignored"));
        }
コード例 #11
0
        public void Test_FloatCanBeRead(string testData, float expected)
        {
            var parser = new MvxStringToTypeParser();

            Assert.AreEqual(expected, parser.ReadValue(testData, typeof(float), "ignored"));
        }
コード例 #12
0
        public void Test_DoubleCanBeRead(string testData, double expected)
        {
            var parser = new MvxStringToTypeParser();

            Assert.AreEqual(expected, parser.ReadValue(testData, typeof(double), "ignored"));
        }