コード例 #1
0
ファイル: StrReadWriteTests.cs プロジェクト: ikvm/StackXML
        public static void Write()
        {
            using var writer = new StrWriter(' ');
            writer.PutString("hello");
            writer.PutString("world");
            writer.PutDouble(5.6);
            writer.PutInt(255);

            var built = writer.ToString();

            Assert.Equal(c_target, built);
        }
コード例 #2
0
ファイル: StructuredStr.cs プロジェクト: ikvm/StackXML
        public static void RoundTrip()
        {
            const char separator = '/';

            var input = new GeneratedClass
            {
                m_int     = int.MaxValue,
                m_double  = 3.14,
                m_string  = "hello world",
                m_spanStr = new SpanStr("span string")
            };

            var writer = new StrWriter(separator);

            input.Serialize(ref writer);

            var  builtString     = writer.ToString();
            bool exceptionThrown = false;

            try
            {
                writer.PutRaw('\0');
                Assert.True(false); // lol
            } catch (ObjectDisposedException)
            {
                exceptionThrown = true;
                // good
            }
            Assert.True(exceptionThrown);
            var reader = new StrReader(builtString.AsSpan(), separator);

            var output = new GeneratedClass();

            output.Deserialize(ref reader);

            Assert.Equal(input.m_int, output.m_int);
            Assert.Equal(input.m_double, output.m_double);
            Assert.Equal(input.m_string, output.m_string);
            Assert.Equal(input.m_spanStr.ToString(), output.m_spanStr.ToString());
        }
コード例 #3
0
        public void AssignProperties()
        {
            if (!ResponseValid)
            {
                return;
            }

            InitProperties();

            DateTime dt;

            if (!string.IsNullOrEmpty(StrReleased) && DateTime.TryParse(StrReleased, CultureInfo.InvariantCulture, DateTimeStyles.AssumeLocal, out dt))
            {
                Released = dt;
            }
            if (!string.IsNullOrEmpty(StrDVD) && DateTime.TryParse(StrDVD, CultureInfo.InvariantCulture, DateTimeStyles.AssumeLocal, out dt))
            {
                DVDRelease = dt;
            }

            int i;

            if (!string.IsNullOrEmpty(StrYear) && !StrYear.Contains("-") && int.TryParse(StrYear, out i))
            {
                Year = i;
            }
            if (!string.IsNullOrEmpty(StrYear) && StrYear.Contains("-") && int.TryParse(StrYear.Split('-')[0], out i))
            {
                Year = i;
            }
            if (!string.IsNullOrEmpty(StrYear) && StrYear.Contains("-") && int.TryParse(StrYear.Split('-')[1], out i))
            {
                EndYear = i;
            }
            if (!string.IsNullOrEmpty(StrYear) && StrYear.Contains("�") && int.TryParse(StrYear.Split('�')[0], out i))
            {
                Year = i;
            }
            if (!string.IsNullOrEmpty(StrYear) && StrYear.Contains("�") && int.TryParse(StrYear.Split('�')[1], out i))
            {
                EndYear = i;
            }
            if (!string.IsNullOrEmpty(StrRuntime) && StrRuntime.EndsWith("min", StringComparison.InvariantCultureIgnoreCase) &&
                int.TryParse(StrRuntime.Remove(StrRuntime.Length - 3).Trim(), out i))
            {
                Runtime = i;
            }
            if (!string.IsNullOrEmpty(StrImdbVotes) && int.TryParse(StrImdbVotes, out i))
            {
                ImdbVotes = i;
            }
            if (!string.IsNullOrEmpty(StrTomatoMeter) && int.TryParse(StrTomatoMeter, out i))
            {
                TomatoMeter = i;
            }
            if (!string.IsNullOrEmpty(StrTomatoReviews) && int.TryParse(StrTomatoReviews, out i))
            {
                TomatoTotalReviews = i;
            }
            if (!string.IsNullOrEmpty(StrTomatoFresh) && int.TryParse(StrTomatoFresh, out i))
            {
                TomatoFreshReviews = i;
            }
            if (!string.IsNullOrEmpty(StrTomatoRotten) && int.TryParse(StrTomatoRotten, out i))
            {
                TomatoRottenReviews = i;
            }
            if (!string.IsNullOrEmpty(StrTomatoUserMeter) && int.TryParse(StrTomatoUserMeter, out i))
            {
                TomatoUserMeter = i;
            }
            if (!string.IsNullOrEmpty(StrTomatoUserReviews) && int.TryParse(StrTomatoUserReviews, out i))
            {
                TomatoUserTotalReviews = i;
            }

            double d;

            if (!string.IsNullOrEmpty(StrImdbRating) && double.TryParse(StrImdbRating, NumberStyles.Float, CultureInfo.InvariantCulture, out d))
            {
                ImdbRating = d;
            }
            if (!string.IsNullOrEmpty(StrTomatoRating) && double.TryParse(StrTomatoRating, NumberStyles.Float, CultureInfo.InvariantCulture, out d))
            {
                TomatoRating = d;
            }
            if (!string.IsNullOrEmpty(StrBoxOffice) && StrBoxOffice.StartsWith("$", StringComparison.InvariantCultureIgnoreCase) &&
                StrBoxOffice.EndsWith("M", StringComparison.InvariantCultureIgnoreCase) &&
                double.TryParse(StrBoxOffice.Substring(1, StrImdbRating.Length - 2), NumberStyles.Float, CultureInfo.InvariantCulture, out d))
            {
                Revenue = Convert.ToInt64(d * 1000000);
            }

            string[] strings = null;
            if (!string.IsNullOrEmpty(StrGenre))
            {
                strings = StrGenre.Split(',');
            }
            if (strings != null)
            {
                Genres = new List <string>(strings).Select(s => CleanString(s)).Distinct().ToList();
            }

            strings = null;
            if (!string.IsNullOrEmpty(StrDirector))
            {
                strings = StrDirector.Split(',');
            }
            if (strings != null)
            {
                Directors = new List <string>(strings).Select(s => CleanString(s)).Distinct().ToList();
            }

            strings = null;
            if (!string.IsNullOrEmpty(StrWriter))
            {
                strings = StrWriter.Split(',');
            }
            if (strings != null)
            {
                Writers = new List <string>(strings).Select(s => CleanString(s)).Distinct().ToList();
            }

            strings = null;
            if (!string.IsNullOrEmpty(StrActors))
            {
                strings = StrActors.Split(',');
            }
            if (strings != null)
            {
                Actors = new List <string>(strings).Select(s => CleanString(s)).Distinct().ToList();
            }
        }