// Methods .................................................... public string GetConfigItemValue(string configKey) { string itemValue = String.Empty; UserConfigItem cfgItem = ConfigItems.FirstOrDefault(s => s.ConfigKey == configKey); if (cfgItem != null) { itemValue = cfgItem.ConfigValue; } return(itemValue); }
private static ClientConfigItem GetConfig(Type contract) { var t = contract; ClientConfigItem item; if (_clientConfigItems.TryGetValue(t.TypeHandle, out item)) { return(item); } var assemblyName = t.Assembly.FullName.Split(',')[0].Trim(); var typeName = t.FullName; var q = ConfigItems.FirstOrDefault(c => (c.Type == typeName && c.Assembly == assemblyName));// || ); if (q != null) { item = new ClientConfigItem { Address = q.Address, Assembly = q.Assembly }; } else { q = ConfigItems.FirstOrDefault(c => c.Assembly == assemblyName && c.Type == string.Empty); if (q != null) { item = new ClientConfigItem { BaseAddress = q.Address, Assembly = q.Assembly }; } else { var temp = GetDefaultConfig(); item = new ClientConfigItem { BaseAddress = temp.BaseAddress, Assembly = temp.Assembly }; } } _clientConfigItems.TryAdd(t.TypeHandle, item); return(item); }
private static ClientConfigItem GetDefaultConfig() { if (defaultConfig == null) { var item = ConfigItems.FirstOrDefault(c => c.Assembly == "*"); if (item != null) { defaultConfig = new ClientConfigItem { BaseAddress = item.Address, Assembly = item.Assembly } } ; else { defaultConfig = new ClientConfigItem(); } } return(defaultConfig); }
private void SetConfigItem(UserConfigItem configItem) { // determine if the config item already exists UserConfigItem cfgItem = ConfigItems.FirstOrDefault(s => s.ConfigKey == configItem.ConfigKey); // Create or update if (cfgItem == null) { cfgItem = new UserConfigItem() { ConfigKey = configItem.ConfigKey, ConfigValue = configItem.ConfigValue }; // Add element to the list ConfigItems.Add(cfgItem); } else { // Update exiting element in list cfgItem.ConfigValue = configItem.ConfigValue; } }