提交 69a8e2a3 编写于 作者: T tanghai

配置文件相关类调试OK,配置文件使用mongodb的json格式,既可作为文件存放也可放到mongodb数据库中,格式一致,非常方便使用

上级 53a7803a
......@@ -32,8 +32,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Game", "Game", "{D0CC1FF4-2
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BehaviorTree", "Game\BehaviorTree\BehaviorTree.csproj", "{C4E7A34A-095C-4983-AB63-FC2D20CD6824}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "World", "Game\World\World.csproj", "{CBEDBE33-A883-4BFA-AE0A-8B3573F09BD0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ENetExe", "Platform\ENetExe\ENetExe.csproj", "{CBA52DC8-1C80-4A79-9AC5-73514EBBD749}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{2814EB55-E1C2-4751-AC14-94116DA9D22B}"
......@@ -140,18 +138,6 @@ Global
{C4E7A34A-095C-4983-AB63-FC2D20CD6824}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{C4E7A34A-095C-4983-AB63-FC2D20CD6824}.Release|Win32.ActiveCfg = Release|Any CPU
{C4E7A34A-095C-4983-AB63-FC2D20CD6824}.Release|x86.ActiveCfg = Release|Any CPU
{CBEDBE33-A883-4BFA-AE0A-8B3573F09BD0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CBEDBE33-A883-4BFA-AE0A-8B3573F09BD0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CBEDBE33-A883-4BFA-AE0A-8B3573F09BD0}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{CBEDBE33-A883-4BFA-AE0A-8B3573F09BD0}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{CBEDBE33-A883-4BFA-AE0A-8B3573F09BD0}.Debug|Win32.ActiveCfg = Debug|Any CPU
{CBEDBE33-A883-4BFA-AE0A-8B3573F09BD0}.Debug|x86.ActiveCfg = Debug|Any CPU
{CBEDBE33-A883-4BFA-AE0A-8B3573F09BD0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CBEDBE33-A883-4BFA-AE0A-8B3573F09BD0}.Release|Any CPU.Build.0 = Release|Any CPU
{CBEDBE33-A883-4BFA-AE0A-8B3573F09BD0}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{CBEDBE33-A883-4BFA-AE0A-8B3573F09BD0}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{CBEDBE33-A883-4BFA-AE0A-8B3573F09BD0}.Release|Win32.ActiveCfg = Release|Any CPU
{CBEDBE33-A883-4BFA-AE0A-8B3573F09BD0}.Release|x86.ActiveCfg = Release|Any CPU
{CBA52DC8-1C80-4A79-9AC5-73514EBBD749}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CBA52DC8-1C80-4A79-9AC5-73514EBBD749}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CBA52DC8-1C80-4A79-9AC5-73514EBBD749}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
......@@ -260,7 +246,6 @@ Global
{D0B4CFAC-A368-4742-9863-68776CFA9938} = {ADBF5F67-B480-4A93-9D50-C81856FC61A9}
{901A8E5C-C4C6-4C3C-8E18-068D75119F5D} = {ADBF5F67-B480-4A93-9D50-C81856FC61A9}
{C4E7A34A-095C-4983-AB63-FC2D20CD6824} = {D0CC1FF4-2747-4278-A51F-BE9AA959175B}
{CBEDBE33-A883-4BFA-AE0A-8B3573F09BD0} = {D0CC1FF4-2747-4278-A51F-BE9AA959175B}
{CBA52DC8-1C80-4A79-9AC5-73514EBBD749} = {ADBF5F67-B480-4A93-9D50-C81856FC61A9}
{B42D431A-3A54-4649-942A-C5356D7F9FBC} = {ADBF5F67-B480-4A93-9D50-C81856FC61A9}
{F176D1FA-63E5-4B89-9A03-D44CCCCC069A} = {ADBF5F67-B480-4A93-9D50-C81856FC61A9}
......
{
"_id" : 1,
"Type" : 0,
"Name" : "yun",
"Duration" : 1500,
}
\ No newline at end of file
{
{
"_id": 1
"Type" : 1
}
\ No newline at end of file
......@@ -46,7 +46,6 @@
<ItemGroup>
<Compile Include="BehaviorTree.cs" />
<Compile Include="BlackBoard.cs" />
<Compile Include="NodeConfig.cs" />
<Compile Include="Node.cs" />
<Compile Include="BehaviorTreeFactory.cs" />
<Compile Include="NodeAttribute.cs" />
......@@ -60,6 +59,10 @@
<Project>{19f8f043-1f99-4550-99df-dea5c7d77e55}</Project>
<Name>Common</Name>
</ProjectReference>
<ProjectReference Include="..\Model\Model.csproj">
<Project>{0FA529D1-D0A9-4A8E-90F5-117CE80F2EDE}</Project>
<Name>Model</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
......
using System;
using System.Collections.Generic;
using System.Reflection;
using Model;
namespace BehaviorTree
{
......
using System.Collections.Generic;
using Model;
namespace BehaviorTree
{
......
namespace BehaviorTree
using Model;
namespace BehaviorTree
{
[Node(NodeType.Not)]
public class Not: Node
......
namespace BehaviorTree
using Model;
namespace BehaviorTree
{
[Node(NodeType.Selector)]
public class Selector: Node
......
namespace BehaviorTree
using Model;
namespace BehaviorTree
{
[Node(NodeType.Sequence)]
internal class Sequence: Node
......
......@@ -4,6 +4,19 @@ namespace Model
{
public class Buff: Object
{
public BuffType Type { get; set; }
private int ConfigId { get; set; }
public Buff(int configId)
{
this.ConfigId = configId;
}
public BuffConfig Config
{
get
{
return World.Instance.ConfigManager.Get<BuffConfig>(this.ConfigId);
}
}
}
}
\ No newline at end of file
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using Common.Base;
using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;
......@@ -11,14 +12,14 @@ namespace Model
[BsonElement]
private HashSet<Buff> Buffs { get; set; }
private Dictionary<ObjectId, Buff> buffGuidDict { get; set; }
private Dictionary<ObjectId, Buff> buffIdDict { get; set; }
private MultiMap<BuffType, Buff> buffTypeMMap { get; set; }
public BuffComponent()
{
this.Buffs = new HashSet<Buff>();
this.buffGuidDict = new Dictionary<ObjectId, Buff>();
this.buffIdDict = new Dictionary<ObjectId, Buff>();
this.buffTypeMMap = new MultiMap<BuffType, Buff>();
}
......@@ -26,43 +27,36 @@ namespace Model
{
foreach (var buff in this.Buffs)
{
this.buffGuidDict.Add(buff.Guid, buff);
this.buffTypeMMap.Add(buff.Type, buff);
this.buffIdDict.Add(buff.Id, buff);
this.buffTypeMMap.Add(buff.Config.Type, buff);
}
}
public bool Add(Buff buff)
public void Add(Buff buff)
{
if (this.Buffs.Contains(buff))
{
return false;
}
if (this.buffGuidDict.ContainsKey(buff.Guid))
{
return false;
throw new ArgumentException(string.Format("already exist same buff, Id: {0} ConfigId: {1}", buff.Id, buff.Config.Id));
}
if (this.buffTypeMMap.GetOne(buff.Type) != null)
if (this.buffIdDict.ContainsKey(buff.Id))
{
return false;
throw new ArgumentException(string.Format("already exist same buff, Id: {0} ConfigId: {1}", buff.Id, buff.Config.Id));
}
this.Buffs.Add(buff);
this.buffGuidDict.Add(buff.Guid, buff);
this.buffTypeMMap.Add(buff.Type, buff);
return true;
this.buffIdDict.Add(buff.Id, buff);
this.buffTypeMMap.Add(buff.Config.Type, buff);
}
public Buff GetByGuid(ObjectId guid)
public Buff GetById(ObjectId id)
{
if (!this.buffGuidDict.ContainsKey(guid))
if (!this.buffIdDict.ContainsKey(id))
{
return null;
}
return this.buffGuidDict[guid];
return this.buffIdDict[id];
}
public Buff GetOneByType(BuffType type)
......@@ -83,15 +77,15 @@ namespace Model
}
this.Buffs.Remove(buff);
this.buffGuidDict.Remove(buff.Guid);
this.buffTypeMMap.Remove(buff.Type, buff);
this.buffIdDict.Remove(buff.Id);
this.buffTypeMMap.Remove(buff.Config.Type, buff);
return true;
}
public bool RemoveByGuid(ObjectId guid)
public bool RemoveById(ObjectId id)
{
Buff buff = this.GetByGuid(guid);
Buff buff = this.GetById(id);
return this.Remove(buff);
}
......
using System.Collections.Generic;
using Common.Config;
namespace Model
{
public class BuffConfig: AConfig
{
public BuffType Type { get; set; }
public string Name { get; set; }
public long Duration { get; set; }
public int MaxStack { get; set; }
public List<int> Effects { get; set; }
public BuffConfig()
{
this.Effects = new List<int>();
}
}
[Config]
public class BuffCategory : ACategory<BuffConfig>
{
}
}
......@@ -15,18 +15,18 @@ namespace Model
public void Add(GameObject gameObject)
{
this.gameObjects.Add(gameObject.Guid, gameObject);
this.gameObjects.Add(gameObject.Id, gameObject);
if (!this.typeGameObjects.ContainsKey(gameObject.Type))
{
this.typeGameObjects.Add(gameObject.Type, new Dictionary<ObjectId, GameObject>());
}
this.typeGameObjects[gameObject.Type].Add(gameObject.Guid, gameObject);
this.typeGameObjects[gameObject.Type].Add(gameObject.Id, gameObject);
}
public GameObject Get(ObjectId guid)
public GameObject Get(ObjectId id)
{
GameObject gameObject = null;
this.gameObjects.TryGetValue(guid, out gameObject);
this.gameObjects.TryGetValue(id, out gameObject);
return gameObject;
}
......@@ -46,20 +46,20 @@ namespace Model
{
throw new ArgumentNullException("gameObject");
}
if (!this.gameObjects.Remove(gameObject.Guid))
if (!this.gameObjects.Remove(gameObject.Id))
{
return false;
}
if (!this.typeGameObjects[gameObject.Type].Remove(gameObject.Guid))
if (!this.typeGameObjects[gameObject.Type].Remove(gameObject.Id))
{
return false;
}
return true;
}
public bool Remove(ObjectId guid)
public bool Remove(ObjectId id)
{
GameObject gameObject = this.Get(guid);
GameObject gameObject = this.Get(id);
if (gameObject == null)
{
return false;
......
using Common.Config;
namespace World.Config
namespace Model
{
public class GlobalConfig: IConfig
public class GlobalConfig: AConfig
{
public int Id { get; set; }
public int Type { get; set; }
}
[Config]
......
......@@ -47,9 +47,13 @@
<ItemGroup>
<Compile Include="Buff.cs" />
<Compile Include="BuffComponent.cs" />
<Compile Include="BuffConfig.cs" />
<Compile Include="BuffType.cs" />
<Compile Include="GameObject.cs" />
<Compile Include="GameObjectManager.cs" />
<Compile Include="GlobalConfig.cs" />
<Compile Include="NodeConfig.cs" />
<Compile Include="World.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="Properties\" />
......
......@@ -2,12 +2,10 @@
using Common.Config;
using MongoDB.Bson.Serialization.Attributes;
namespace BehaviorTree
namespace Model
{
public class NodeConfig: IConfig
public class NodeConfig: AConfig
{
public int Id { get; set; }
[BsonIgnoreIfNull]
public List<string> Args { get; set; }
......
using Common.Config;
using Model;
namespace World
namespace Model
{
public class World
{
private static readonly World instance = new World();
private readonly ConfigManager configManager = new ConfigManager();
private readonly ConfigManager configManager = ConfigManager.Instance;
private readonly GameObjectManager gameObjectManager = new GameObjectManager();
......
......@@ -21,12 +21,12 @@ namespace MongoDBTest
var collection = database.GetCollection<GameObject>("GameObjects");
GameObject player1 = GameObjectFactory.CreatePlayer();
player1.GetComponent<BuffComponent>().Add(new Buff());
player1.GetComponent<BuffComponent>().Add(new Buff(1));
player1["hp"] = 10;
collection.Insert(player1);
var query = Query<GameObject>.EQ(e => e.Guid, player1.Guid);
var query = Query<GameObject>.EQ(e => e.Id, player1.Id);
GameObject player2 = collection.FindOne(query);
Console.WriteLine(MongoHelper.ToJson(player2));
......
using System.Reflection;
using System.Runtime.InteropServices;
// 有关程序集的常规信息通过以下
// 特性集控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("Component")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Component")]
[assembly: AssemblyCopyright("Copyright © 2013")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// 将 ComVisible 设置为 false 使此程序集中的类型
// 对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型,
// 则将该类型上的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("55cc5b17-d8c8-4c34-922c-47afac13d174")]
// 程序集的版本信息由下面四个值组成:
//
// 主版本
// 次版本
// 生成号
// 修订号
//
// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
// 方法是按如下所示使用“*”:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{CBEDBE33-A883-4BFA-AE0A-8B3573F09BD0}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>World</RootNamespace>
<AssemblyName>World</AssemblyName>
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
<RestorePackages>true</RestorePackages>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\..\Bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\..\Bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
</ItemGroup>
<ItemGroup>
<Compile Include="Config\GlobalConfig.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="World.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Platform\Common\Common.csproj">
<Project>{19f8f043-1f99-4550-99df-dea5c7d77e55}</Project>
<Name>Common</Name>
</ProjectReference>
<ProjectReference Include="..\Model\Model.csproj">
<Project>{0fa529d1-d0a9-4a8e-90f5-117ce80f2ede}</Project>
<Name>Model</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
\ No newline at end of file
......@@ -3,6 +3,9 @@ using MongoDB.Bson.Serialization.Attributes;
namespace Common.Base
{
/// <summary>
/// Component的Id与Owner Entity Id一样
/// </summary>
public abstract class Component : Object, ISupportInitialize
{
private Entity owner;
......@@ -17,7 +20,7 @@ namespace Common.Base
set
{
this.owner = value;
this.Guid = this.owner.Guid;
this.Id = this.owner.Id;
}
}
......
......@@ -21,6 +21,12 @@ namespace Common.Base
public void AddComponent<T>() where T : Component, new()
{
if (this.ComponentDict.ContainsKey(typeof (T)))
{
throw new Exception(
string.Format("AddComponent, component already exist, id: {0}, component: {1}",
this.Id, typeof(T).Name));
}
T t = new T { Owner = this };
this.Components.Add(t);
this.ComponentDict.Add(typeof (T), t);
......@@ -29,7 +35,13 @@ namespace Common.Base
public void RemoveComponent<T>() where T : Component
{
Component t;
this.ComponentDict.TryGetValue(typeof(T), out t);
if (!this.ComponentDict.TryGetValue(typeof (T), out t))
{
throw new Exception(
string.Format("RemoveComponent, component not exist, id: {0}, component: {1}",
this.Id, typeof(T).Name));
}
this.Components.Remove(t);
this.ComponentDict.Remove(typeof(T));
}
......@@ -39,7 +51,9 @@ namespace Common.Base
Component t;
if (!this.ComponentDict.TryGetValue(typeof (T), out t))
{
return null;
throw new Exception(
string.Format("GetComponent, component not exist, id: {0}, component: {1}",
this.Id, typeof(T).Name));
}
return (T) t;
}
......@@ -57,8 +71,8 @@ namespace Common.Base
{
foreach (Component component in this.Components)
{
this.ComponentDict.Add(component.GetType(), component);
component.Owner = this;
this.ComponentDict.Add(component.GetType(), component);
}
}
}
......
......@@ -7,7 +7,7 @@ namespace Common.Base
public abstract class Object
{
[BsonId]
public ObjectId Guid { get; protected set; }
public ObjectId Id { get; protected set; }
[BsonElement]
[BsonIgnoreIfNull]
......@@ -15,12 +15,12 @@ namespace Common.Base
protected Object()
{
this.Guid = ObjectId.GenerateNewId();
this.Id = ObjectId.GenerateNewId();
}
protected Object(ObjectId guid)
protected Object(ObjectId id)
{
this.Guid = guid;
this.Id = id;
}
public object this[string key]
......
......@@ -70,7 +70,7 @@
<Compile Include="Config\ConfigAttribute.cs" />
<Compile Include="Config\ACategory.cs" />
<Compile Include="Config\ConfigManager.cs" />
<Compile Include="Config\IConfig.cs" />
<Compile Include="Config\AConfig.cs" />
<Compile Include="Helper\BigIntegerHelper.cs" />
<Compile Include="Helper\ByteHelper.cs" />
<Compile Include="Helper\EnumHelper.cs" />
......
......@@ -6,13 +6,13 @@ using Common.Helper;
namespace Common.Config
{
public abstract class ACategory<T>: ICategory where T : IConfig
public abstract class ACategory<T>: ICategory where T : AConfig
{
protected readonly Dictionary<int, T> dict = new Dictionary<int, T>();
public void BeginInit()
public virtual void BeginInit()
{
string path = Path.Combine(@"./Config/", this.Name);
string path = Path.Combine(@"../../Config/", typeof(T).Name);
if (!Directory.Exists(path))
{
......@@ -26,23 +26,23 @@ namespace Common.Config
}
}
public void EndInit()
{
}
public T this[int type]
public Type ConfigType
{
get
{
return this.dict[type];
return typeof (T);
}
}
public string Name
public virtual void EndInit()
{
}
public T this[int type]
{
get
{
return typeof (T).Name;
return this.dict[type];
}
}
......
using System.ComponentModel;
using MongoDB.Bson.Serialization.Attributes;
namespace Common.Config
{
public abstract class AConfig: ISupportInitialize
{
[BsonId]
public int Id { get; set; }
public virtual void BeginInit()
{
}
public virtual void EndInit()
{
}
}
}
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.Reflection;
using Common.Logger;
namespace Common.Config
{
public class ConfigManager
{
public Dictionary<string, object> allConfig;
private static ConfigManager instance = new ConfigManager();
public static ConfigManager Instance
{
get
{
return instance;
}
}
public Dictionary<Type, ICategory> allConfig;
private ConfigManager()
{
}
public void Load(Assembly assembly)
{
var localAllConfig = new Dictionary<string, object>();
var localAllConfig = new Dictionary<Type, ICategory>();
Type[] types = assembly.GetTypes();
foreach (var type in types)
foreach (Type type in types)
{
object[] attrs = type.GetCustomAttributes(typeof (ConfigAttribute), false);
Log.Debug(type.Name);
if (attrs.Length == 0)
{
continue;
......@@ -25,34 +41,45 @@ namespace Common.Config
ICategory iCategory = obj as ICategory;
if (iCategory == null)
{
throw new Exception(string.Format("class: {0} not inherit from ACategory",
type.Name));
throw new Exception(
string.Format("class: {0} not inherit from ACategory", type.Name));
}
iCategory.BeginInit();
iCategory.EndInit();
localAllConfig[type.Name] = obj;
localAllConfig[iCategory.ConfigType] = iCategory;
}
this.allConfig = localAllConfig;
}
public T Get<T>(int type) where T : IConfig
public T Get<T>(int id) where T : AConfig
{
var configCategory = (ACategory<T>) this.allConfig[typeof (T).Name];
return configCategory[type];
Type type = typeof (T);
ICategory configCategory;
if (!this.allConfig.TryGetValue(type, out configCategory))
{
throw new KeyNotFoundException(string.Format("ConfigManager not found key: {0}", type.FullName));
}
return ((ACategory<T>) configCategory)[id];
}
public T[] GetAll<T>() where T : IConfig
public T[] GetAll<T>() where T : AConfig
{
var configCategory = (ACategory<T>) this.allConfig[typeof (T).Name];
return configCategory.GetAll();
Type type = typeof(T);
ICategory configCategory;
if (!this.allConfig.TryGetValue(type, out configCategory))
{
throw new KeyNotFoundException(string.Format("ConfigManager not found key: {0}", type.FullName));
}
return ((ACategory<T>)configCategory).GetAll();
}
public T GetCategory<T>() where T : class, ICategory, new()
{
T t = new T();
object category;
bool ret = this.allConfig.TryGetValue(t.Name, out category);
Type type = t.ConfigType;
ICategory category;
bool ret = this.allConfig.TryGetValue(type, out category);
return ret? (T) category : null;
}
}
......
using System.ComponentModel;
using System;
using System.ComponentModel;
namespace Common.Config
{
public interface ICategory: ISupportInitialize
{
string Name { get; }
Type ConfigType { get; }
}
}
\ No newline at end of file
namespace Common.Config
{
public interface IConfig
{
int Id { get; }
}
}
\ No newline at end of file
......@@ -55,7 +55,6 @@
</Choose>
<ItemGroup>
<Compile Include="ENetClientServerTest.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Common\Common.csproj">
......@@ -67,6 +66,9 @@
<Name>ENet</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Folder Include="Properties\" />
</ItemGroup>
<Choose>
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
<ItemGroup>
......
using System.Reflection;
using System.Runtime.InteropServices;
// 有关程序集的常规信息通过以下特性集
// 控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("ENetCSTest")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft")]
[assembly: AssemblyProduct("ENetCSTest")]
[assembly: AssemblyCopyright("Copyright © Microsoft 2012")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// 将 ComVisible 设置为 false 会使此程序集中的类型
// 对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型,
// 请将该类型上的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("b52f4804-3f6e-4268-810a-08fe8ca12bd0")]
// 程序集的版本信息由以下四个值组成:
//
// 主版本
// 次版本
// 生成号
// 修订号
//
// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
// 方法是按如下所示使用“*”:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册