65 lines
1.6 KiB
Plaintext
65 lines
1.6 KiB
Plaintext
using System;
|
||
using System.Collections.Generic;
|
||
using MongoDB.Bson.Serialization.Attributes;
|
||
using MongoDB.Bson.Serialization.Options;
|
||
using System.ComponentModel;
|
||
|
||
namespace ET
|
||
{
|
||
[Config]
|
||
public partial class (ConfigName)Category : Singleton<(ConfigName)Category>, IMerge
|
||
{
|
||
[BsonElement]
|
||
[BsonDictionaryOptions(DictionaryRepresentation.ArrayOfArrays)]
|
||
private Dictionary<int, (ConfigName)> dict = new();
|
||
|
||
public void Merge(object o)
|
||
{
|
||
(ConfigName)Category s = o as (ConfigName)Category;
|
||
foreach (var kv in s.dict)
|
||
{
|
||
this.dict.Add(kv.Key, kv.Value);
|
||
}
|
||
}
|
||
|
||
public (ConfigName) Get(int id)
|
||
{
|
||
this.dict.TryGetValue(id, out (ConfigName) item);
|
||
|
||
if (item == null)
|
||
{
|
||
throw new Exception($"配置找不到,配置表名: {nameof ((ConfigName))},配置id: {id}");
|
||
}
|
||
|
||
return item;
|
||
}
|
||
|
||
public bool Contain(int id)
|
||
{
|
||
return this.dict.ContainsKey(id);
|
||
}
|
||
|
||
public Dictionary<int, (ConfigName)> GetAll()
|
||
{
|
||
return this.dict;
|
||
}
|
||
|
||
public (ConfigName) GetOne()
|
||
{
|
||
if (this.dict == null || this.dict.Count <= 0)
|
||
{
|
||
return null;
|
||
}
|
||
|
||
var enumerator = this.dict.Values.GetEnumerator();
|
||
enumerator.MoveNext();
|
||
return enumerator.Current;
|
||
}
|
||
}
|
||
|
||
public partial class (ConfigName): ProtoObject, IConfig
|
||
{
|
||
(Fields)
|
||
}
|
||
}
|