| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- using Azylee.Core.AppUtils.AppConfigUtils.AppConfigInterfaces;
- using Azylee.Core.DataUtils.CollectionUtils;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace Azylee.Core.AppUtils.AppConfigUtils.AppConfigModels
- {
- /// <summary>
- /// 配置块模型
- /// </summary>
- /// <typeparam name="T"></typeparam>
- public class AppConfigRegionModel<T> where T : IAppConfigItemModel
- {
- public List<T> Items { get; set; }
- public AppConfigRegionModel()
- {
- this.Items = new List<T>();
- }
- public bool HasItems()
- {
- return Ls.Ok(Items);
- }
- public void AddItem(T item, bool overwrite = false)
- {
- bool repeat = false;
- for (int i = 0; i < Items.Count; i++)
- {
- if (Items[i].GetUniqueName() == item.GetUniqueName())
- {
- if (overwrite) { Items[i] = item; }
- repeat = true;
- }
- }
- if (!repeat) { this.Items.Add(item); }
- }
- public void RemoveItem(string name)
- {
- for (int i = 0; i < Items.Count; i++)
- {
- if (Items[i].GetUniqueName() == name)
- {
- Items.RemoveAt(i);
- break;
- }
- }
- }
- public T GetItem(string name)
- {
- for (int i = 0; i < Items.Count; i++)
- {
- if (Items[i].GetUniqueName() == name)
- {
- return Items[i];
- }
- }
- return default(T);
- }
- public void OrderByNumber()
- {
- Items = Items.OrderBy(x => x.GetOrderNumber()).ThenBy(x => x.GetUniqueName()).ToList();
- }
- public List<string> GetNames()
- {
- List<string> rs = new List<string>();
- foreach (var item in Items)
- {
- rs.Add(item.GetUniqueName());
- }
- return rs;
- }
- }
- }
|