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

namespace TD.SandDock
{
	internal class ControlLayoutSystemConverter : TypeConverter
	{
		public virtual bool a(ITypeDescriptorContext A_0, Type A_1)
		{
			return A_1 == typeof(InstanceDescriptor) || base.CanConvertTo(A_0, A_1);
		}

		public virtual object a(ITypeDescriptorContext A_0, CultureInfo A_1, object A_2, Type A_3)
		{
			if (A_3 == null)
			{
				throw new ArgumentNullException();
			}
			if (A_3 == typeof(InstanceDescriptor) && A_2 is ControlLayoutSystem)
			{
				ControlLayoutSystem controlLayoutSystem = (ControlLayoutSystem)A_2;
				MemberInfo constructor = A_2.GetType().GetConstructor(new Type[]
				{
					typeof(int),
					typeof(int),
					typeof(DockControl[]),
					typeof(DockControl)
				});
				DockControl[] array = new DockControl[checked((uint)controlLayoutSystem.Controls.Count)];
				controlLayoutSystem.Controls.CopyTo(array, 0);
				object[] arguments = new object[]
				{
					(int)controlLayoutSystem.f.Width,
					(int)controlLayoutSystem.f.Height,
					array,
					controlLayoutSystem.SelectedControl
				};
				if (constructor != null)
				{
					return new InstanceDescriptor(constructor, arguments);
				}
			}
			return base.ConvertTo(A_0, A_1, A_2, A_3);
		}
	}
}
