Пример #1
0
        /// <summary>
        /// Loading contentm from Format and convert it
        /// to Nda model
        /// </summary>
        private void LoadContentToFile(Type entryType)
        {
            var fullContent = FileFormat.GetContent();
            var enumerable  = fullContent as IList <IEnumerable <string> > ?? fullContent.ToList();

            Titles = enumerable.First().ToList();
            foreach (var singleEntry in enumerable.Skip(1))
            {
                var entry = Activator.CreateInstance(entryType);
                var index = 0;
                foreach (var entryPart in singleEntry)
                {
                    var propertyname =
                        (from prop in entryType.GetProperties()
                         from attr in prop.GetCustomAttributes(typeof(TitleName), false)
                         where ((TitleName)attr).Name == Titles[index]
                         select prop.Name).FirstOrDefault();
                    if (propertyname != null)
                    {
                        var    propertyType = entryType.GetProperty(propertyname).PropertyType.Name;
                        object value        = GetValue(entryPart, propertyType);
                        entryType.GetProperty(propertyname).SetValue(entry, value, null);
                    }
                    index++;
                }
                Content.Add(entry as AEntry);
            }
        }
Пример #2
0
        /// <summary>
        /// Loading contentm from Format and convert it
        /// to Nda model using dynamic object to represent it
        /// </summary>
        private void LoadContentToFileDynamic()
        {
            var fullContent = FileFormat.GetContent();
            var enumerable  = fullContent as IList <IEnumerable <string> > ?? fullContent.ToList();

            Titles = enumerable.First().ToList();
            foreach (var singleNdaEntry in enumerable.Skip(1))
            {
                dynamic ndaEntry = new DynamicEntry();
                var     index    = 0;
                foreach (var entryPart in singleNdaEntry)
                {
                    ndaEntry.SetProperty(Titles[index].Replace(" ", ""), entryPart);
                    index++;
                }
                DynamicContent.Add(ndaEntry);
            }
        }
Пример #3
0
        /// <summary>
        /// Loading contentm from Format and convert it
        /// to Nda model
        /// </summary>
        private void LoadContentToFile(Type entryType)
        {
            var fullContent = FileFormat.GetContent();
            var enumerable  = fullContent as IList <IEnumerable <string> > ?? fullContent.ToList();

            Titles = enumerable.First().ToList();
            foreach (var singleEntry in enumerable.Skip(1))
            {
                var entry = Activator.CreateInstance(entryType);
                var index = 0;
                foreach (var entryPart in singleEntry)
                {
                    var propertyname =
                        (from prop in entryType.GetProperties()
                         from attr in prop.GetCustomAttributes(typeof(TitleName), false)
                         where ((TitleName)attr).Name == Titles[index]
                         select prop.Name).First();
                    var    propertyType = entryType.GetProperty(propertyname).PropertyType.Name;
                    object value;
                    if (propertyType.ToLower().Contains("string"))
                    {
                        value = entryPart;
                    }
                    else if (propertyType.ToLower().Contains("datetime"))
                    {
                        value = DateTime.Parse(entryPart);
                    }
                    else
                    {
                        if (entryPart == "")
                        {
                            value = null;
                        }
                        else
                        {
                            value = Convert.ToInt16(entryPart);
                        }
                    }
                    entryType.GetProperty(propertyname).SetValue(entry, value, null);
                    index++;
                }
                Content.Add(entry as AEntry);
            }
        }