Inheritance: JsonConverter
Exemple #1
0
        public List <RecordError> Validate(List <string> content)
        {
            List <RecordError> list = new List <RecordError>();

            foreach (string record in content)
            {
                try
                {
                    if (record.Length < 95 || record.Length > 95)
                    {
                        RecordError model = new RecordError();
                        model.Error = "Tamanho do registro inválido.";
                        model.Line  = content.IndexOf(record);
                        model.Field = "Linha";
                        list.Add(model);
                    }

                    RecordConverter recordConverter = new RecordConverter();
                    InvoiceData     separeteContent = recordConverter.ToInvoiceData(record);

                    RecordValidator recordValidator = new RecordValidator();
                    recordValidator.Validate(separeteContent, content.IndexOf(record));
                }
                catch (Exception.RecordValidatorException ex)
                {
                    list.AddRange(ex.Model);
                }
                catch (System.Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

            return(list);
        }
        public void Rec_HappyExpando()
        {
            converter = new DataConverter(
                IdentityConverter.Instance,
                new TryParseConverter(),
                new ToStringConverter(true),
                RecordConverter.ForReadOnlyDictionaries(),
                RecordConverter.ForDictionaries(),
                ToObjectConverter.Instance,
                new DynamicConverter());

            var     e = new ExpandoObject();
            dynamic d = e;

            d.FirstName = "Joost";
            d.LastName  = "Morsink";
            d.Age       = 38;
            Assert.IsTrue(converter.Convert(e).TryTo(out PersonS p));
            Assert.AreEqual("Joost", p.FirstName);
            Assert.AreEqual("Morsink", p.LastName);
            Assert.AreEqual(38, p.Age);
            Assert.IsTrue(converter.Convert(p).TryTo(out e));
            d = e;
            Assert.AreEqual("Joost", d.FirstName);
            Assert.AreEqual("Morsink", d.LastName);
            Assert.AreEqual(38, d.Age);
        }
 public void Init()
 {
     converter = new DataConverter(
         IdentityConverter.Instance,
         new TryParseConverter(),
         new ToStringConverter(true),
         RecordConverter.ForReadOnlyDictionaries(),
         RecordConverter.ForDictionaries(),
         new DynamicConverter());
 }
 public void Rec_StaticUnhappy()
 {
     Assert.IsFalse(RecordConverter.ForDictionaries().CanConvert(typeof(object), typeof(Dictionary <string, string>)));
     Assert.IsFalse(RecordConverter.ForDictionaries().CanConvert(typeof(Dictionary <string, string>), typeof(object)));
 }