using System;
using System.Collections.Generic;
using System.Reflection;

namespace QC.XmlToDBPreProcess;

public static class PreProcessorUtils
{
	public static string GetPropertyValue(object obj, string fieldName)
	{
		Type type = obj.GetType();
		PropertyInfo property = type.GetProperty(fieldName);
		if (property != null)
		{
			return property.GetValue(obj, null)?.ToString();
		}
		return null;
	}

	public static bool PropertyExists(object obj, string propertyName)
	{
		Type type = obj.GetType();
		PropertyInfo property = type.GetProperty(propertyName);
		return property != null;
	}

	public static Dictionary<string, string> NameValueSeperator(string[] keyValuePairs)
	{
		Dictionary<string, string> dictionary = new Dictionary<string, string>();
		string[] separator = new string[1] { "=" };
		foreach (string text in keyValuePairs)
		{
			string[] array = text.Split(separator, StringSplitOptions.RemoveEmptyEntries);
			if (array.Length == 2 && !dictionary.ContainsKey(array[0]))
			{
				dictionary.Add(array[0], array[1]);
			}
		}
		return dictionary;
	}
}
