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

提取出AMongo和IMongo两个基类:

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