コード例 #1
0
        public override object CreateInstance(ITypeDescriptorContext context, IDictionary propertyValues)
        {
            IOOutput io = new IOOutput();

            io.CardNo       = (CardNo)propertyValues["CardNo"];
            io.AxisNo       = (int)propertyValues["AxisNo"];
            io.OuputNo      = (OutputNo)propertyValues["OuputNo"];
            io.DefaultState = (bool)propertyValues["DefaultState"];
            return(io);
        }
コード例 #2
0
        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
        {
            //将对象转换为字符串
            if ((destinationType == typeof(string)) && value != null && value != null)
            {
                return(((IOOutput)value).ToString());
            }

            //生成设计时的构造器代码
            if (destinationType == typeof(InstanceDescriptor) && value != null)
            {
                IOOutput        p    = (IOOutput)value;
                ConstructorInfo ctor = typeof(IOOutput).GetConstructor(new Type[] { typeof(CardNo), typeof(int), typeof(OutputNo), typeof(bool) });
                return(new InstanceDescriptor(ctor, new object[] { p.CardNo, p.AxisNo, p.OuputNo, p.DefaultState }));
            }

            return(base.ConvertTo(context, culture, value, destinationType));
        }