using System;
using System.ComponentModel;
using System.Reflection;
using QC.QsprTestObjects.Parameters;
using QC.QsprTestObjects.Tests.Base;

namespace QC.QsprTestObjects.Tests.DotNet;

[Serializable]
public class DotNetTestProperties : TestProperties
{
	private string failString = "False";

	private bool createNewInstance;

	[DefaultValue("False")]
	[Category("Dot Net Test Settings")]
	[Description("Regular expression string for the test failure.\nThe method's return value is matched with this string.")]
	public string FailString
	{
		get
		{
			return failString;
		}
		set
		{
			failString = value;
		}
	}

	[Description("If TRUE creates new instance of the class before executing the test.")]
	[Category("Dot Net Test Settings")]
	[DefaultValue(false)]
	public bool CreateNewInstance
	{
		get
		{
			return createNewInstance;
		}
		set
		{
			createNewInstance = value;
		}
	}

	[Category("Dot Net Test Settings")]
	[ReadOnly(true)]
	public string MinDllVersion { get; set; }

	[Category("Dot Net Test Settings")]
	[ReadOnly(true)]
	public string DllName { get; set; }

	public DotNetTestProperties()
	{
	}

	public DotNetTestProperties(TestProperties original)
	{
		PropertyInfo[] properties = GetType().GetProperties();
		foreach (PropertyInfo propertyInfo in properties)
		{
			PropertyInfo property = original.GetType().GetProperty(propertyInfo.Name);
			if (property != null)
			{
				object value = propertyInfo.GetValue(original, null);
				propertyInfo.SetValue(this, value, null);
			}
		}
	}

	public DotNetTestProperties(TestProperties primarySource, TestProperties secondarySource)
	{
		PropertyInfo[] properties = GetType().GetProperties();
		foreach (PropertyInfo propertyInfo in properties)
		{
			if (!propertyInfo.CanWrite)
			{
				continue;
			}
			PropertyInfo property = secondarySource.GetType().GetProperty(propertyInfo.Name);
			if (property != null)
			{
				object value = propertyInfo.GetValue(secondarySource, null);
				propertyInfo.SetValue(this, value, null);
			}
			PropertyInfo property2 = primarySource.GetType().GetProperty(propertyInfo.Name);
			if (property2 != null)
			{
				object value2 = propertyInfo.GetValue(primarySource, null);
				if (value2 != null && (!(value2 is string) || !string.IsNullOrWhiteSpace(value2 as string)) && !(value2 is ParameterCollection) && !(propertyInfo.Name == "RealName"))
				{
					propertyInfo.SetValue(this, value2, null);
				}
			}
		}
	}

	public override TestProperties Clone()
	{
		DotNetTestProperties dotNetTestProperties = new DotNetTestProperties();
		dotNetTestProperties.failString = failString;
		dotNetTestProperties.CreateNewInstance = CreateNewInstance;
		dotNetTestProperties.DllName = DllName;
		dotNetTestProperties.MinDllVersion = MinDllVersion;
		Copy(dotNetTestProperties);
		return dotNetTestProperties;
	}
}
