Quellcode durchsuchen

提取出AMongo和IMongo两个基类:
1.AMongo: 需要序列化并且需要存储 Key Value 数据的类继承此抽象类
2.IMongo: 需要序列化的成员继承此接口
区别是AMongo比IMongo多带一个Object类

tanghai vor 11 Jahren
Ursprung
Commit
17e7b152cc

+ 4 - 1
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

+ 16 - 0
CSharp/Platform/Common/Base/AMongo.cs

@@ -0,0 +1,16 @@
+namespace Common.Base
+{
+    /// <summary>
+    /// 需要序列化并且需要存储 Key Value 数据的类继承此抽象类
+    /// </summary>
+    public abstract class AMongo: Object, IMongo
+    {
+        public virtual void BeginInit()
+        {
+        }
+
+        public virtual void EndInit()
+        {
+        }
+    }
+}

+ 2 - 11
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
 {
     /// <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()
-        {
-        }
     }
 }

+ 2 - 7
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<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)
             {

+ 11 - 0
CSharp/Platform/Common/Base/IMongo.cs

@@ -0,0 +1,11 @@
+using System.ComponentModel;
+
+namespace Common.Base
+{
+    /// <summary>
+    /// 需要序列化的成员继承此接口
+    /// </summary>
+    public interface IMongo: ISupportInitialize
+    {
+    }
+}

+ 2 - 0
CSharp/Platform/Common/Common.csproj

@@ -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" />

+ 2 - 2
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; }