1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
| using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Games.ClassLibrary.Network
{
public class CommandParser
{
public string Method { get; set; }
public Dictionary<string, string[]> Parameters { get; set; }
public string CommandInLine { get; set; }
public CommandParser(string Method, Dictionary<string, string[]> Parameters)
{
this.Method = Method;
this.Parameters = Parameters;
this.CommandInLine = this.EncodCommand();
}
public CommandParser(string CommandInLine)
{
this.CommandInLine = CommandInLine;
string Method = string.Empty;
Dictionary<string, string[]> Parameters = null;
this.DecodeCommand(out Method, out Parameters);
this.Method = Method;
this.Parameters = Parameters;
}
private string EncodCommand()
{
List<string> serializedParameter = new List<string>();
foreach (KeyValuePair<string, string[]> parameter in this.Parameters)
{
serializedParameter.Add(String.Format("{0}:{1}", parameter.Key, string.Join(",", parameter.Value)));
}
return String.Format("Method:{0},Parameters:[{1}]", this.Method, string.Join(",", serializedParameter));
}
private void DecodeCommand(out string Method, out Dictionary<string, string[]> Parameters)
{
Method = string.Empty;
Parameters = null;
}
}
} |
Partager