Exemplo n.º 1
0
        public IEnumerable <T> GetAll <T>() where T : Model
        {
            Type     type  = typeof(T);
            XmlNode  root  = GetTypeNodeItemsSection(type, document);
            List <T> items = new List <T>();

            for (int i = 0; i < root.ChildNodes.Count; i++)
            {
                XmlNode xmlNode = root.ChildNodes[i];
                T       item    = typeof(T).GetConstructor(Type.EmptyTypes).Invoke(null) as T;
                var     values  = GetPropertyValuesFromNode(xmlNode);
                ReflectionParser.SetPropertiesValues <T>(item, values);
                items.Add(item);
            }
            return(items);
        }
Exemplo n.º 2
0
        public T Get <T>(int id) where T : Model
        {
            Type    type = typeof(T);
            XmlNode root = GetTypeNodeItemsSection(type, document);

            XmlNode itemNode = GetNodeById(id, root.ChildNodes);

            if (itemNode != null)
            {
                T   item   = typeof(T).GetConstructor(Type.EmptyTypes).Invoke(null) as T;
                var values = GetPropertyValuesFromNode(itemNode);
                ReflectionParser.SetPropertiesValues <T>(item, values);
                return(item);
            }
            return(null);
        }