using System;
using System.Reflection;
using QC.QTMDotNetKernelInterface;
using QC.QTMDotNetKernelInterface.Environment;

namespace QC.QTMDotNetKernel.Registry;

public class TestProperty : MarshalByRefObject
{
	private string name;

	private bool isTestParameter;

	private TestParameter parameter;

	private PropertyInfo pInfo;

	private TestClass parent;

	private string testList = "";

	public PropertyInfo PropertyInfo
	{
		get
		{
			return pInfo;
		}
		set
		{
			pInfo = value;
		}
	}

	public TestParameter Parameter
	{
		get
		{
			return parameter;
		}
		set
		{
			parameter = value;
		}
	}

	public TestClass Parent
	{
		get
		{
			return parent;
		}
		set
		{
			parent = value;
		}
	}

	public string Name
	{
		get
		{
			return name;
		}
		set
		{
			name = value;
		}
	}

	public bool IsTestParameter
	{
		get
		{
			return isTestParameter;
		}
		set
		{
			isTestParameter = value;
		}
	}

	public string TestList
	{
		get
		{
			return testList.Trim();
		}
		set
		{
			testList = value.Trim();
		}
	}

	public TestProperty()
	{
	}

	public TestProperty(PropertyInfo pInfo, out bool created)
	{
		created = true;
		name = pInfo.Name;
		parameter = new TestParameter(pInfo.Name);
		this.pInfo = pInfo;
		if (pInfo.CanWrite)
		{
			parameter.IOType = "Input";
		}
		else
		{
			parameter.IOType = "Output";
		}
		parameter.Type = pInfo.PropertyType;
		if (parameter.DataType == null)
		{
			created = false;
		}
	}

	public bool Contains(string testName)
	{
		try
		{
			if (testList.Length == 0)
			{
				return true;
			}
			string[] array = testList.Split(',');
			string[] array2 = array;
			foreach (string text in array2)
			{
				if (text.Trim() == testName.Trim())
				{
					return true;
				}
			}
		}
		catch
		{
		}
		return false;
	}

	public void ApplyAttributes()
	{
		try
		{
			MemberInfo[] member = Parent.TestType.GetMember(Name);
			object[] customAttributes = member[0].GetCustomAttributes(inherit: false);
			object[] array = customAttributes;
			for (int i = 0; i < array.Length; i++)
			{
				Attribute attribute = (Attribute)array[i];
				if (attribute is QTMParameter)
				{
					isTestParameter = true;
					QTMParameter qTMParameter = (QTMParameter)attribute;
					TestMethod.SetParamAttributes(qTMParameter, parameter);
					if (parameter.IsArray)
					{
						parameter.NumberOfElements = qTMParameter.NumberOfElements;
					}
					else
					{
						parameter.NumberOfElements = 1;
					}
					parameter.IOType = qTMParameter.IOType.ToString();
					TestList = qTMParameter.TestList;
				}
				else if (attribute is QSPREnvInfo)
				{
					_ = Parent.Instance is QSPRTest;
				}
			}
		}
		catch
		{
		}
	}
}
