SafeSet/SafeGet replaced with this[]
This commit is contained in:
parent
1cfca90b8d
commit
07e88dc8a7
4 changed files with 36 additions and 34 deletions
|
|
@ -9,7 +9,7 @@ using HttpServer.Headers;
|
|||
using Newtonsoft.Json;
|
||||
using HttpListener = HttpServer.HttpListener;
|
||||
|
||||
namespace TShockAPI
|
||||
namespace Rests
|
||||
{
|
||||
/// <summary>
|
||||
/// Rest command delegate
|
||||
|
|
@ -146,18 +146,18 @@ namespace TShockAPI
|
|||
{
|
||||
public string Status
|
||||
{
|
||||
get { return SafeGet("status"); }
|
||||
set { SafeSet("status", value); }
|
||||
get { return this["status"]; }
|
||||
set { this["status"] = value; }
|
||||
}
|
||||
public string Error
|
||||
{
|
||||
get { return SafeGet("error"); }
|
||||
set { SafeSet("error", value); }
|
||||
get { return this["error"]; }
|
||||
set { this["error"] = value; }
|
||||
}
|
||||
public string Response
|
||||
{
|
||||
get { return SafeGet("response"); }
|
||||
set { SafeSet("response", value); }
|
||||
get { return this["response"]; }
|
||||
set { this["response"] = value; }
|
||||
}
|
||||
|
||||
public RestObject(string status)
|
||||
|
|
@ -166,23 +166,21 @@ namespace TShockAPI
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets value safely.
|
||||
/// Gets value safely, if it does not exist, return null. Sets/Adds value safely, if null it will remove.
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="value"></param>
|
||||
/// <returns>Returns null if key does not exist.</returns>
|
||||
public string SafeGet(string key)
|
||||
public new string this[string key]
|
||||
{
|
||||
get
|
||||
{
|
||||
string ret;
|
||||
if (TryGetValue(key, out ret))
|
||||
return ret;
|
||||
return null;
|
||||
}
|
||||
/// <summary>
|
||||
/// Sets/Adds value safely. If null it will remove.
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="value"></param>
|
||||
public void SafeSet(string key, string value)
|
||||
set
|
||||
{
|
||||
if (!ContainsKey(key))
|
||||
{
|
||||
|
|
@ -193,12 +191,13 @@ namespace TShockAPI
|
|||
else
|
||||
{
|
||||
if (value != null)
|
||||
this[key] = value;
|
||||
base[key] = value;
|
||||
else
|
||||
Remove(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class RestCommand
|
||||
{
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||
using System.Linq;
|
||||
using System.Text;
|
||||
using HttpServer;
|
||||
using Rests;
|
||||
using Terraria;
|
||||
|
||||
namespace TShockAPI {
|
||||
|
|
|
|||
|
|
@ -4,8 +4,9 @@ using System.Linq;
|
|||
using System.Net;
|
||||
using System.Text;
|
||||
using HttpServer;
|
||||
using TShockAPI;
|
||||
|
||||
namespace TShockAPI
|
||||
namespace Rests
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
|
|
@ -66,7 +67,7 @@ namespace TShockAPI
|
|||
|
||||
Tokens.Add(hash, user);
|
||||
|
||||
obj.SafeSet("token", hash);
|
||||
obj["token"] = hash;
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ using System.Threading;
|
|||
using Community.CsharpSqlite.SQLiteClient;
|
||||
using HttpServer;
|
||||
using MySql.Data.MySqlClient;
|
||||
using Rests;
|
||||
using Terraria;
|
||||
using TerrariaAPI;
|
||||
using TerrariaAPI.Hooks;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue