Refactoring.Utils.StandardFormatter.Deserialize C# (CSharp) 메소드

Deserialize() 공개 메소드

public Deserialize ( SerializedData serializedData ) : Customer
serializedData SerializedData
리턴 Customer
        public Customer Deserialize(SerializedData serializedData)
        {
            string standardData = serializedData.StandardData;
            string name = Regex.Match(standardData, @"\b\w+\n", RegexOptions.Compiled).ToString().TrimEnd('\n');
            var customer = new Customer(name);

            var movieTitles = Regex.Matches(standardData, @"\t(.*?)\t", RegexOptions.Compiled);
            var moviePrices = Regex.Matches(standardData, @"\t\d+[,.]?(\d+)?\n", RegexOptions.Compiled);

            if (movieTitles.Count != moviePrices.Count)
            {
                throw new ArgumentException("data");
            }

            for (int i = 0; i < movieTitles.Count; ++i)
            {
                customer.Movies.Add(movieTitles[i].ToString().Trim('\t'), Convert.ToDouble(moviePrices[i].ToString().Trim('\t', '\n')));
            }

            string totalAmounAsString = Regex.Match(standardData, @" \d+[,.]?(\d+)?\n", RegexOptions.Compiled).ToString().TrimEnd('\n');
            customer.TotalAmount = Convert.ToDouble(totalAmounAsString);
            customer.FrequentRenterPoints = Convert.ToInt32(Regex.Match(standardData, @" (\d+) ", RegexOptions.Compiled).ToString());

            return customer;
        }

Usage Example

예제 #1
0
        public void CompositeFormatter_WhenCustomerHaveMultipleRentals_ShouldPass()
        {
            var jsonFormatter = new JsonFormatter();
            var xmlFormatter = new XmlFormatter();
            var standardFormatter = new StandardFormatter();
            var compositeFormatter = new CompositeFormatter();

            compositeFormatter.AddFormatter(new JsonFormatter());
            compositeFormatter.AddFormatter(new StandardFormatter());
            compositeFormatter.AddFormatter(new XmlFormatter());

            var customer = CustomerFactory.GetCustomer();
            var serializedData = customer.GetStatement(compositeFormatter);
            Customer actualFromJson = jsonFormatter.Deserialize(serializedData);
            Customer actualFromXml = xmlFormatter.Deserialize(serializedData);
            Customer actualFromStandard = standardFormatter.Deserialize(serializedData);

            Assert.True(customer.Equals(actualFromJson));
            Assert.True(customer.Equals(actualFromXml));
            Assert.True(customer.Equals(actualFromStandard));
        }
All Usage Examples Of Refactoring.Utils.StandardFormatter::Deserialize
StandardFormatter