초기커밋
This commit is contained in:
43
ServerCommon/Helper/ConfigHelper.cs
Normal file
43
ServerCommon/Helper/ConfigHelper.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
|
||||
|
||||
using ServerCore;
|
||||
|
||||
|
||||
|
||||
using WORLD_META_ID = System.UInt32;
|
||||
using CHANNEL_NO = System.UInt32;
|
||||
|
||||
|
||||
namespace ServerCommon;
|
||||
|
||||
public static class ConfigHelper
|
||||
{
|
||||
public static WORLD_META_ID getWorldId(this IConfiguration config)
|
||||
{
|
||||
return uint.Parse(config["worldId"] ?? "0");
|
||||
}
|
||||
|
||||
public static ushort getPort(this IConfiguration config)
|
||||
{
|
||||
return ushort.Parse(config["port"] ?? "0");
|
||||
}
|
||||
|
||||
public static CHANNEL_NO getChannelNo(this IConfiguration config)
|
||||
{
|
||||
return uint.Parse(config["channelNo"] ?? "0");
|
||||
}
|
||||
|
||||
public static ServerType getServerType(this IConfiguration config)
|
||||
{
|
||||
var value = config["config"];
|
||||
|
||||
if (Enum.TryParse<ServerType>(value, true, out var serverType))
|
||||
{
|
||||
return serverType;
|
||||
}
|
||||
|
||||
throw new Exception($"Invalid or missing ServerType in IConfiguration:{value}");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user