using System; using System.ComponentModel; using System.ComponentModel.Design.Serialization; using System.Globalization; using System.Reflection; namespace DevComponents.DotNetBar { /// /// Represents DocumentBarContainer converter. /// public class DocumentBarContainerConverter:TypeConverter { /// /// Creates new instance of the class. /// public DocumentBarContainerConverter(){} /// /// Checks whether conversion can be made to specified type. /// /// Context Information. /// Destination type. /// public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) { if(destinationType==typeof(InstanceDescriptor)) return true; return base.CanConvertTo(context, destinationType); } /// /// Converts object to specified type. /// /// Context information. /// Culture information. /// Object to convert. /// Destination type. /// Object converted to destination type. public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { if(destinationType==null) throw new ArgumentNullException("destinationType"); if((destinationType==typeof(InstanceDescriptor)) && (value is DocumentBarContainer)) { DocumentBarContainer doc=(DocumentBarContainer)value; Type[] constructorParams=null; MemberInfo constructorMemberInfo = null; object[] constructorValues = null; constructorParams = new Type[3] { typeof(Bar),typeof(int),typeof(int) } ; constructorMemberInfo = typeof(DocumentBarContainer).GetConstructor(constructorParams); constructorValues=new object[3] {doc.Bar,doc.LayoutBounds.Width,doc.LayoutBounds.Height}; if(constructorMemberInfo!=null) { return new InstanceDescriptor(constructorMemberInfo, constructorValues); } } return base.ConvertTo(context, culture, value, destinationType); } } }