chatr/ChatrServer/Chatr/Arguments.cs

61 lines
1.5 KiB
C#
Raw Permalink Normal View History

2022-08-24 11:34:56 +00:00
using System.Collections.Generic;
using System;
namespace Tesses.Chatr.Server
{
public class Arguments
{
public Arguments(string[] args)
{
//--key={value}
foreach(var arg in args)
{
string[] argument=arg.Split(new char[]{'='},2,StringSplitOptions.RemoveEmptyEntries);
if(argument.Length >= 1)
{
string key=argument[0];
string value=null;
if(argument.Length ==2) value=argument[1];
}
}
}
private Dictionary<string,string> _args=new Dictionary<string, string>();
public IReadOnlyDictionary<string,string> ArgumentList {get{return _args;}}
public static implicit operator Dictionary<string,string>(Arguments args)
{
Dictionary<string,string> dict=new Dictionary<string, string>();
foreach(var di in args.ArgumentList)
{
dict.Add(di.Key,di.Value);
}
return dict;
}
public bool ContainsKey(string key)
{
return ArgumentList.ContainsKey(key);
}
public bool TryGetValue(string key,out string value)
{
return ArgumentList.TryGetValue(key,out value);
}
public bool TryGetValueNotNull(string key,out string value)
{
string value0;
if(TryGetValue(key,out value0))
{
if(!string.IsNullOrWhiteSpace(value0)) {value=value0; return true;}
}
value="";
return false;
}
}
}