using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
#pragma warning disable CS8604 // Possible null reference argument.
namespace EasyDevCore.Common
{
///
///
///
public static class ArgumentHelper
{
///
/// Outs the specified alias.
///
///
/// The object.
/// The name.
///
public static T Out(this T obj, out T @name)
{
@name = obj;
return obj;
}
///
/// Outs the specified selector.
///
///
/// The type of the result.
/// The object.
/// The selector.
/// The name.
///
public static T Out(this T obj, Func selector, out TResult @name)
{
@name = selector(obj);
return obj;
}
///
/// Gets the arguments has value pair format
/// Ex1: new { Name = ... }
/// Ex2: "Name1,Name2", "a", "b"
///
/// The arguments.
///
public static IDictionary GetArgValues(params object[] args)
{
IDictionary values = new Dictionary();
if (args.Length == 1)
{
return args[0].GetPropertyValues();
}
else
{
if (args[0] is not string)
{
throw new ArgumentException(args[0].GetTypeName() + " is not supported !");
}
var names = (args[0] as string).SplitByCommaOrSemiColon();
if (names.Length != args.Length - 1)
{
throw new ArgumentException("Length of paramNames and values are not the same !");
}
for (int i = 0; i < names.Length; i++)
{
values.Add(names[i], args[i + 1]);
}
return values;
}
}
}
}