예제 #1
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (base.Request["types"] == null)
     {
         throw new BadQueryParameterException("types");
     }
     try
     {
         StringArrayConverter stringArrayConverter = new StringArrayConverter();
         this.Value = (string[])stringArrayConverter.ConvertFrom(base.Request["types"]);
     }
     catch (NotSupportedException innerException)
     {
         throw new BadQueryParameterException("types", innerException);
     }
     try
     {
         foreach (string value2 in this.Value)
         {
             Enum.Parse(typeof(KindKeyword), value2, true);
         }
     }
     catch (ArgumentException innerException2)
     {
         throw new BadQueryParameterException("types", innerException2);
     }
 }
        public void ReturnsEmptyArrayWithEmpty()
        {
            var target = new StringArrayConverter();

            var output = target.ConvertFrom(string.Empty);

            var array = Assert.IsType <string[]>(output);

            Assert.Empty(array);
        }
        public void ReturnsSingleStringWhenThereIsNoDelimeter(string input)
        {
            var target = new StringArrayConverter();

            var output = target.ConvertFrom(input);

            var array = Assert.IsType <string[]>(output);

            Assert.Equal(new[] { input }, array);
        }
        public void SplitsStringBySemicolon()
        {
            var target = new StringArrayConverter();

            var output = target.ConvertFrom("foo;bar  ;  baz");

            var array = Assert.IsType <string[]>(output);

            Assert.Equal(new[] { "foo", "bar  ", "  baz" }, array);
        }
        public void ConvertFromPreservesExtraneousWhitespace()
        {
            object[]             expected = new object[] { "1 ", " Foo ", " 3" };
            StringArrayConverter vrt      = new StringArrayConverter();
            object actual = vrt.ConvertFrom("1 , Foo , 3");

            Assert.IsNotNull(actual);
            Assert.AreEqual(typeof(string[]), actual.GetType());
            Assert.IsTrue(ArrayUtils.AreEqual(expected, (string[])actual),
                          "Individual array elements not correctly converted (check the whitespace?).");
        }
예제 #6
0
        public static string[] ToArrayOfStrings(this string commaSeparatedString)
        {
            if (commaSeparatedString == null)
            {
                return(null);
            }
            StringArrayConverter stringArrayConverter = new StringArrayConverter();

            return((from stringValue in ((string[])stringArrayConverter.ConvertFrom(commaSeparatedString)).AsEnumerable <string>()
                    where stringValue != null && stringValue != string.Empty
                    select stringValue).ToArray <string>());
        }
        public void ConvertFrom()
        {
            object[]             expected = new object[] { "1", "Foo", "3" };
            StringArrayConverter vrt      = new StringArrayConverter();
            object actual = vrt.ConvertFrom("1,Foo,3");

            Assert.IsNotNull(actual);
            Assert.AreEqual(typeof(string[]), actual.GetType());
            Assert.AreEqual(3, ((string[])actual).Length, "Wrong number of elements in the resulting array.");
            Assert.IsTrue(ArrayUtils.AreEqual(expected, (string[])actual),
                          "Individual array elements not correctly converted.");
        }
        public void NullingTheListSeparatorMakesItRevertToTheDefault()
        {
            object[]             expected = new object[] { "1", "Foo", "3" };
            StringArrayConverter vrt      = new StringArrayConverter();

            vrt.ListSeparator = null;
            object actual = vrt.ConvertFrom("1,Foo,3");

            Assert.IsNotNull(actual);
            Assert.AreEqual(typeof(string[]), actual.GetType());
            Assert.IsTrue(ArrayUtils.AreEqual(expected, (string[])actual),
                          "Individual array elements not correctly converted.");
        }
        public void CustomListSeparator()
        {
            object[]             expected        = new object[] { "1", "Foo", "3" };
            StringArrayConverter vrt             = new StringArrayConverter();
            const string         customSeparator = "#";

            vrt.ListSeparator = customSeparator;
            object actual = vrt.ConvertFrom(string.Format("1{0}Foo{0}3", customSeparator));

            Assert.IsNotNull(actual);
            Assert.AreEqual(typeof(string[]), actual.GetType());
            Assert.IsTrue(ArrayUtils.AreEqual(expected, (string[])actual),
                          "Individual array elements not correctly converted.");
        }
        public void EnsureCultureListSeparatorIsIgnored()
        {
            CultureInfo originalCulture = Thread.CurrentThread.CurrentCulture;

            try
            {
                CultureInfo frenchCulture = new CultureInfo("fr-FR");
                Thread.CurrentThread.CurrentCulture = frenchCulture;
                object[]             expected = new object[] { "1", "Foo", "3" };
                StringArrayConverter vrt      = new StringArrayConverter();
                // France uses the ';' (semi-colon) to separate list items...
                object actual = vrt.ConvertFrom("1,Foo,3");
                Assert.IsNotNull(actual);
                Assert.AreEqual(typeof(string[]), actual.GetType());
                Assert.IsTrue(ArrayUtils.AreEqual(expected, (string[])actual),
                              "Individual array elements not correctly converted.");
            }
            finally
            {
                Thread.CurrentThread.CurrentCulture = originalCulture;
            }
        }
예제 #11
0
        public override void LoadSettingsFromStorage()
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            base.LoadSettingsFromStorage();

            var settingsManager   = new ShellSettingsManager(ServiceProvider.GlobalProvider);
            var userSettingsStore = settingsManager.GetWritableSettingsStore(SettingsScope.UserSettings);

            if (!userSettingsStore.PropertyExists(GeneralOptionsCollection, nameof(LibraryPackFiles)))
            {
                _page.LibraryPackFiles = new List <string>();
                return;
            }

            var converter = new StringArrayConverter();

            this.LibraryPackFiles = converter.ConvertFrom(
                userSettingsStore.GetString(GeneralOptionsCollection, nameof(LibraryPackFiles))) as List <string>;
            // for debug
            //LibraryPackFiles.Add("C:\\Users\\Username\\Projects\\lib_hl\\libraries.xml");

            _page.LibraryPackFiles = LibraryPackFiles;
        }
        public void ConvertFromNonSupportedOptionBails()
        {
            StringArrayConverter vrt = new StringArrayConverter();

            vrt.ConvertFrom(12);
        }
        public void ConvertFromNullReference()
        {
            StringArrayConverter vrt = new StringArrayConverter();

            vrt.ConvertFrom(null);
        }