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

namespace TD.SandDock
{
	internal class ControlLayoutSystemConverter : 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 ControlLayoutSystem)
			{
				ControlLayoutSystem controlLayoutSystem = (ControlLayoutSystem)A_2;
				MemberInfo memberInfo = null;
				object[] array = null;
				memberInfo = A_2.GetType().GetConstructor(new Type[4]
				{
					typeof(int),
					typeof(int),
					typeof(DockControl[]),
					typeof(DockControl)
				});
				DockControl[] array2 = new DockControl[checked((uint)controlLayoutSystem.Controls.Count)];
				controlLayoutSystem.Controls.CopyTo(array2, 0);
				array = new object[4]
				{
					(int)((LayoutSystemBase)controlLayoutSystem).f.Width,
					(int)((LayoutSystemBase)controlLayoutSystem).f.Height,
					array2,
					controlLayoutSystem.SelectedControl
				};
				if ((object)memberInfo != null)
				{
					return new InstanceDescriptor(memberInfo, array);
				}
			}
			return base.ConvertTo(A_0, A_1, A_2, A_3);
		}
	}
}
