-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Thiago Zimmermann
committed
Aug 31, 2020
1 parent
368d08c
commit f1c6822
Showing
1 changed file
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
namespace Hypnonema.Client | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel; | ||
using System.Linq; | ||
|
||
using CitizenFX.Core; | ||
|
||
public static class ArgsReader | ||
{ | ||
public static T GetArgKeyValue<T>(IDictionary<string, object> args, string key, T defaultValue) | ||
{ | ||
var result = defaultValue; | ||
|
||
try | ||
{ | ||
var input = args.FirstOrDefault(arg => arg.Key == key).Value?.ToString(); | ||
result = (T)TypeDescriptor.GetConverter(typeof(T)).ConvertFromString(input); | ||
} | ||
catch (Exception) | ||
{ | ||
Debug.WriteLine($"failed to read {key}"); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
public static T GetArgKeyValue<T>(IDictionary<string, object> args, string key) | ||
{ | ||
var result = default(T); | ||
try | ||
{ | ||
result = GetArgKeyValue(args, key, default(T)); | ||
} | ||
catch (Exception) | ||
{ | ||
} | ||
|
||
return result; | ||
} | ||
} | ||
} |