From 17e7b152cc09638f1b0570e2b2f84417b2d9b63b Mon Sep 17 00:00:00 2001 From: tanghai Date: Thu, 16 Oct 2014 17:26:30 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E5=8F=96=E5=87=BAAMongo=E5=92=8CIMong?= =?UTF-8?q?o=E4=B8=A4=E4=B8=AA=E5=9F=BA=E7=B1=BB:=201.AMongo:=20=E9=9C=80?= =?UTF-8?q?=E8=A6=81=E5=BA=8F=E5=88=97=E5=8C=96=E5=B9=B6=E4=B8=94=E9=9C=80?= =?UTF-8?q?=E8=A6=81=E5=AD=98=E5=82=A8=20Key=20Value=20=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E7=9A=84=E7=B1=BB=E7=BB=A7=E6=89=BF=E6=AD=A4=E6=8A=BD=E8=B1=A1?= =?UTF-8?q?=E7=B1=BB=202.IMongo:=20=E9=9C=80=E8=A6=81=E5=BA=8F=E5=88=97?= =?UTF-8?q?=E5=8C=96=E7=9A=84=E6=88=90=E5=91=98=E7=BB=A7=E6=89=BF=E6=AD=A4?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=20=E5=8C=BA=E5=88=AB=E6=98=AFAMongo=E6=AF=94?= =?UTF-8?q?IMongo=E5=A4=9A=E5=B8=A6=E4=B8=80=E4=B8=AAObject=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CSharp/Game/Model/Buff.cs | 5 ++++- CSharp/Platform/Common/Base/AMongo.cs | 16 ++++++++++++++++ CSharp/Platform/Common/Base/Component.cs | 13 ++----------- CSharp/Platform/Common/Base/Entity.cs | 9 ++------- CSharp/Platform/Common/Base/IMongo.cs | 11 +++++++++++ CSharp/Platform/Common/Common.csproj | 2 ++ CSharp/Platform/Common/Config/AConfig.cs | 4 ++-- 7 files changed, 39 insertions(+), 21 deletions(-) create mode 100644 CSharp/Platform/Common/Base/AMongo.cs create mode 100644 CSharp/Platform/Common/Base/IMongo.cs diff --git a/CSharp/Game/Model/Buff.cs b/CSharp/Game/Model/Buff.cs index 552b75f4..a226779b 100644 --- a/CSharp/Game/Model/Buff.cs +++ b/CSharp/Game/Model/Buff.cs @@ -1,9 +1,11 @@ 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 diff --git a/CSharp/Platform/Common/Base/AMongo.cs b/CSharp/Platform/Common/Base/AMongo.cs new file mode 100644 index 00000000..b693035d --- /dev/null +++ b/CSharp/Platform/Common/Base/AMongo.cs @@ -0,0 +1,16 @@ +namespace Common.Base +{ + /// + /// 需要序列化并且需要存储 Key Value 数据的类继承此抽象类 + /// + public abstract class AMongo: Object, IMongo + { + public virtual void BeginInit() + { + } + + public virtual void EndInit() + { + } + } +} \ No newline at end of file diff --git a/CSharp/Platform/Common/Base/Component.cs b/CSharp/Platform/Common/Base/Component.cs index 72498c31..b14b5360 100644 --- a/CSharp/Platform/Common/Base/Component.cs +++ b/CSharp/Platform/Common/Base/Component.cs @@ -1,12 +1,11 @@ -using System.ComponentModel; -using MongoDB.Bson.Serialization.Attributes; +using MongoDB.Bson.Serialization.Attributes; namespace Common.Base { /// /// Component的Id与Owner Entity Id一样 /// - 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 diff --git a/CSharp/Platform/Common/Base/Entity.cs b/CSharp/Platform/Common/Base/Entity.cs index efbd65bd..759af75f 100644 --- a/CSharp/Platform/Common/Base/Entity.cs +++ b/CSharp/Platform/Common/Base/Entity.cs @@ -1,12 +1,11 @@ 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 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) { diff --git a/CSharp/Platform/Common/Base/IMongo.cs b/CSharp/Platform/Common/Base/IMongo.cs new file mode 100644 index 00000000..3006e6d4 --- /dev/null +++ b/CSharp/Platform/Common/Base/IMongo.cs @@ -0,0 +1,11 @@ +using System.ComponentModel; + +namespace Common.Base +{ + /// + /// 需要序列化的成员继承此接口 + /// + public interface IMongo: ISupportInitialize + { + } +} \ No newline at end of file diff --git a/CSharp/Platform/Common/Common.csproj b/CSharp/Platform/Common/Common.csproj index 0529f8b9..afb1f7bc 100644 --- a/CSharp/Platform/Common/Common.csproj +++ b/CSharp/Platform/Common/Common.csproj @@ -58,9 +58,11 @@ + + diff --git a/CSharp/Platform/Common/Config/AConfig.cs b/CSharp/Platform/Common/Config/AConfig.cs index cd169c5f..29353976 100644 --- a/CSharp/Platform/Common/Config/AConfig.cs +++ b/CSharp/Platform/Common/Config/AConfig.cs @@ -1,9 +1,9 @@ -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; } -- GitLab