示例#1
0
        public static IEnumerable <xmlAppSettingsModel> ListarParametros(string configFile)
        {
            List <xmlAppSettingsModel> roboConfig = new List <xmlAppSettingsModel>();
            XElement xml     = XElement.Load(ConfigurationManager.AppSettings.Get(configFile));
            var      element = xml.Element("appSettings");
            var      nodes   = element.Nodes();

            foreach (var x in xml.Element("appSettings").Descendants())
            {
                xmlAppSettingsModel p = new xmlAppSettingsModel()
                {
                    key   = x.Attribute("key").Value,
                    Value = x.Attribute("value").Value,
                };
                roboConfig.Add(p);
            }

            return(roboConfig);
        }
示例#2
0
        public static xmlAppSettingsModel ConsultarNoXml(string key, string configFile)
        {
            try
            {
                XElement xml = XElement.Load(ConfigurationManager.AppSettings.Get(configFile));
                XElement x   = xml.Elements("appSettings")
                               .Descendants()
                               .Where(p => p.Attribute("key").Value.Equals(key)).First();

                var setting = new xmlAppSettingsModel();
                if (x != null)
                {
                    setting.key   = x.Attribute("key").Value;
                    setting.Value = x.Attribute("value").Value;
                }
                return(setting);
            }
            catch (Exception)
            {
                return(new xmlAppSettingsModel());
            }
        }