Use better code
This commit is contained in:
parent
608e7a99bc
commit
75c8a8ced4
32 changed files with 77 additions and 105 deletions
|
|
@ -378,10 +378,10 @@ namespace Rests
|
|||
uri = uri.TrimEnd('/');
|
||||
string upgrade = null;
|
||||
|
||||
if (redirects.ContainsKey(uri))
|
||||
if (redirects.TryGetValue(uri, out var value))
|
||||
{
|
||||
upgrade = redirects[uri].Item2;
|
||||
uri = redirects[uri].Item1;
|
||||
upgrade = value.Item2;
|
||||
uri = value.Item1;
|
||||
}
|
||||
|
||||
foreach (var com in commands)
|
||||
|
|
@ -398,7 +398,7 @@ namespace Rests
|
|||
for (int i = 0; i < com.UriVerbs.Length; i++)
|
||||
verbs.Add(com.UriVerbs[i], match.Groups[i + 1].Value);
|
||||
}
|
||||
else if (com.UriTemplate.ToLower() != uri.ToLower())
|
||||
else if (string.Equals(com.UriTemplate, uri, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1216,7 +1216,7 @@ namespace TShockAPI
|
|||
sb.AppendLine("{0}".SFormat(descattr.Description));
|
||||
|
||||
var permission = method.GetCustomAttributes(false).Where(o => o is Permission);
|
||||
if (permission.Count() > 0)
|
||||
if (permission.Any())
|
||||
{
|
||||
sb.AppendLine(GetString("* **Permissions**: `{0}`", String.Join(", ", permission.Select(p => ((Permission)p).Name))));
|
||||
}
|
||||
|
|
@ -1225,8 +1225,8 @@ namespace TShockAPI
|
|||
sb.AppendLine(GetString("No special permissions are required for this route."));
|
||||
}
|
||||
sb.AppendLine();
|
||||
var verbs = method.GetCustomAttributes(false).Where(o => o is Verb);
|
||||
if (verbs.Count() > 0)
|
||||
var verbs = method.GetCustomAttributes(false).Where(o => o is Verb).Cast<Verb>();
|
||||
if (verbs.Any())
|
||||
{
|
||||
sb.AppendLine(GetString("**Verbs**:"));
|
||||
foreach (Verb verb in verbs)
|
||||
|
|
@ -1238,8 +1238,8 @@ namespace TShockAPI
|
|||
}
|
||||
}
|
||||
sb.AppendLine();
|
||||
var nouns = method.GetCustomAttributes(false).Where(o => o is Noun);
|
||||
if (nouns.Count() > 0)
|
||||
var nouns = method.GetCustomAttributes(false).Where(o => o is Noun).Cast<Noun>();
|
||||
if (nouns.Any())
|
||||
{
|
||||
sb.AppendLine(GetString("**Nouns**:"));
|
||||
foreach (Noun noun in nouns)
|
||||
|
|
@ -1375,7 +1375,7 @@ namespace TShockAPI
|
|||
}
|
||||
foreach (EscapedParameter filter in parameters)
|
||||
{
|
||||
if (player.ContainsKey(filter.Name) && !player[filter.Name].Equals(filter.Value))
|
||||
if (player.TryGetValue(filter.Name, out object value) && !value.Equals(filter.Value))
|
||||
return null;
|
||||
}
|
||||
return player;
|
||||
|
|
|
|||
|
|
@ -63,8 +63,7 @@ namespace Rests
|
|||
{
|
||||
get
|
||||
{
|
||||
object ret;
|
||||
if (TryGetValue(key, out ret))
|
||||
if (TryGetValue(key, out object ret))
|
||||
return ret;
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,8 +36,7 @@ namespace Rests
|
|||
{
|
||||
get
|
||||
{
|
||||
string ret;
|
||||
if (TryGetValue(key, out ret))
|
||||
if (TryGetValue(key, out string ret))
|
||||
{
|
||||
return Uri.UnescapeDataString(ret);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -67,14 +67,10 @@ namespace Rests
|
|||
|
||||
private void AddTokenToBucket(string ip)
|
||||
{
|
||||
if (tokenBucket.ContainsKey(ip))
|
||||
if (!tokenBucket.TryAdd(ip, 1))
|
||||
{
|
||||
tokenBucket[ip] += 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
tokenBucket.Add(ip, 1);
|
||||
}
|
||||
}
|
||||
|
||||
private object DestroyToken(RestRequestArgs args)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue