using System;
using System.ComponentModel;
using System.ComponentModel.Design.Serialization;
using System.Globalization;
using System.Reflection;
using System.Windows.Forms;

namespace TD.SandDock
{
	internal class SplitLayoutSystemConverter : TypeConverter
	{
		public override bool a(ITypeDescriptorContext A_0, Type A_1)
		{
			if ((object)A_1 == typeof(InstanceDescriptor))
			{
				return true;
			}
			return base.CanConvertTo(A_0, A_1);
		}

		public override object a(ITypeDescriptorContext A_0, CultureInfo A_1, object A_2, Type A_3)
		{
			if ((object)A_3 == null)
			{
				throw new ArgumentNullException();
			}
			if ((object)A_3 == typeof(InstanceDescriptor) && A_2 is SplitLayoutSystem)
			{
				SplitLayoutSystem splitLayoutSystem = (SplitLayoutSystem)A_2;
				MemberInfo memberInfo = null;
				object[] array = null;
				if (splitLayoutSystem.LayoutSystems.Count == 0)
				{
					memberInfo = typeof(SplitLayoutSystem).GetConstructor(new Type[2]
					{
						typeof(int),
						typeof(int)
					});
					array = new object[2]
					{
						(int)splitLayoutSystem.f.Width,
						(int)splitLayoutSystem.f.Height
					};
				}
				else
				{
					memberInfo = typeof(SplitLayoutSystem).GetConstructor(new Type[4]
					{
						typeof(int),
						typeof(int),
						typeof(Orientation),
						typeof(LayoutSystemBase[])
					});
					LayoutSystemBase[] array2 = new LayoutSystemBase[checked((uint)splitLayoutSystem.LayoutSystems.Count)];
					splitLayoutSystem.LayoutSystems.CopyTo(array2, 0);
					array = new object[4]
					{
						(int)splitLayoutSystem.f.Width,
						(int)splitLayoutSystem.f.Height,
						splitLayoutSystem.SplitMode,
						array2
					};
				}
				if ((object)memberInfo != null)
				{
					return new InstanceDescriptor(memberInfo, array);
				}
			}
			return base.ConvertTo(A_0, A_1, A_2, A_3);
		}
	}
}
