using System.Collections;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Diagnostics.CodeAnalysis;
using static System.Console;
public static class MyParser
public static void Parse<T>(string name, T value)
Console.WriteLine($"{name}: single");
public static void ParseEnumerable<T>(string name, IEnumerable<T> enumerable)
Console.WriteLine($"{name}: IEnumerable<{typeof(T)}>");
public static void ParseCollection<T>(string name, T collection)
var itemType = collection.GetType().GenericTypeArguments.FirstOrDefault();
.GetMethod("ParseEnumerable")
.MakeGenericMethod(itemType)
.Invoke(null, new object[] { name, collection });
.GetMethod("AsEnumerable")
.MakeGenericMethod(collection.GetType().GetElementType())
.Invoke(null, new object[] { collection });
.GetMethod("ParseEnumerable")
.MakeGenericMethod(collection.GetType().GetElementType())
.Invoke(null, new object[] { name, result });
public static void ParseObj<T>(T data)
foreach (var prop in data.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public))
if (prop.PropertyType == typeof(string))
Parse(prop.Name, prop.GetValue(data, null));
else if (typeof (IEnumerable).IsAssignableFrom(prop.PropertyType))
ParseCollection(prop.Name, prop.GetValue(data, null));
Parse(prop.Name, prop.GetValue(data, null));
public static void Main()
Str = "abc", Num = 543, Arr = new[]{1, 2, 3}, Chars = new char[]{'x', 'y', 'z'}, SomeList = new List<string>()