提交 17e7b152 编写于 作者: T tanghai

提取出AMongo和IMongo两个基类:

1.AMongo: 需要序列化并且需要存储 Key Value 数据的类继承此抽象类
2.IMongo: 需要序列化的成员继承此接口
区别是AMongo比IMongo多带一个Object类
上级 69a8e2a3
using Common.Base;
using MongoDB.Bson.Serialization.Attributes;
namespace Model
{
public class Buff: Object
public class Buff: AMongo
{
[BsonElement]
private int ConfigId { get; set; }
public Buff(int configId)
......@@ -11,6 +13,7 @@ namespace Model
this.ConfigId = configId;
}
[BsonIgnore]
public BuffConfig Config
{
get
......
namespace Common.Base
{
/// <summary>
/// 需要序列化并且需要存储 Key Value 数据的类继承此抽象类
/// </summary>
public abstract class AMongo: Object, IMongo
{
public virtual void BeginInit()
{
}
public virtual void EndInit()
{
}
}
}
\ No newline at end of file
using System.ComponentModel;
using MongoDB.Bson.Serialization.Attributes;
using MongoDB.Bson.Serialization.Attributes;
namespace Common.Base
{
/// <summary>
/// Component的Id与Owner Entity Id一样
/// </summary>
public abstract class Component : Object, ISupportInitialize
public abstract class Component : AMongo
{
private Entity owner;
......@@ -23,13 +22,5 @@ namespace Common.Base
this.Id = this.owner.Id;
}
}
public virtual void BeginInit()
{
}
public virtual void EndInit()
{
}
}
}
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using MongoDB.Bson.Serialization.Attributes;
namespace Common.Base
{
public abstract class Entity : Object, ISupportInitialize
public abstract class Entity : AMongo
{
[BsonElement]
private HashSet<Component> Components { get; set; }
......@@ -63,11 +62,7 @@ namespace Common.Base
return this.Components.ToArray();
}
public virtual void BeginInit()
{
}
public virtual void EndInit()
public override void EndInit()
{
foreach (Component component in this.Components)
{
......
using System.ComponentModel;
namespace Common.Base
{
/// <summary>
/// 需要序列化的成员继承此接口
/// </summary>
public interface IMongo: ISupportInitialize
{
}
}
\ No newline at end of file
......@@ -58,9 +58,11 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Base\IMongo.cs" />
<Compile Include="Base\Entity.cs" />
<Compile Include="Base\Component.cs" />
<Compile Include="Base\MultiMap.cs" />
<Compile Include="Base\AMongo.cs" />
<Compile Include="Config\ICategory.cs" />
<Compile Include="Event\EventTrigger.cs" />
<Compile Include="Event\Env.cs" />
......
using System.ComponentModel;
using Common.Base;
using MongoDB.Bson.Serialization.Attributes;
namespace Common.Config
{
public abstract class AConfig: ISupportInitialize
public abstract class AConfig : IMongo
{
[BsonId]
public int Id { get; set; }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册