Skip to content

Commit

Permalink
add missing ArgsReader.cs file
Browse files Browse the repository at this point in the history
  • Loading branch information
Thiago Zimmermann committed Aug 31, 2020
1 parent 368d08c commit f1c6822
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/Hypnonema.Client/ArgsReader.cs
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;
}
}
}

0 comments on commit f1c6822

Please sign in to comment.