类型转换做误 System.NotSupportedException: “TypeConverter”

using System;
using System.ComponentModel.Design.Serialization;
using System.ComponentModel;


namespace  test
{

 public class TSoInfo
 {
  public string Brush;
 }

 public class TConvert
 {
  [STAThread]
  static void Main(string[] args)
  {
   
   InstanceDescriptor td = new InstanceDescriptor(null,null,false);

   TSoInfo t=  new TSoInfo();

   TypeConverter   tc= new TypeConverter();

   tc.ConvertTo(null, null, t, td.GetType());

  }

 }

}

/*
 *
 * 未处理的异常: System.NotSupportedException: “TypeConverter”无法将“test.TSoIn
fo”转换为“System.ComponentModel.Design.Serialization.InstanceDescriptor”。
   at System.ComponentModel.TypeConverter.GetConvertToException(Object value, Ty
pe destinationType)
   at System.ComponentModel.TypeConverter.ConvertTo(ITypeDescriptorContext conte
xt, CultureInfo culture, Object value, Type destinationType)
   at test.TConvert.Main(String[] args) in e:/TNC/cs/Project2/tsoinfo.cs:l
ine 26

 * */

 

  • Download component source files - 58 Kb
  • Download component demo project - 33.5 Kb 
  •  
  •  
  •  
  •  
  • Info1: 
  •   如果我自定义一个控件,它当中的一个复杂属性的类型是自定义类,我现在对这个自定义类定义一个TypeConverter,请问我如何能使这个复杂属性像Font、Size属性一样,在属性窗口中显示一个"+"?

  • ---------------------------------------------------------
    Info2:  
    InstanceDescriptor   可以存储描述对象实例的信息。这些信息可用于创建对象的实例。  
      某些自定义序列化程序使用   InstanceDescriptor   来表示可序列化的对象。TypeDescriptor   的若干方法使用   InstanceDescriptor   来表示或实例化对象。  
       
      InstanceDescriptor   提供以下成员:    
       
      描述此对象的   MemberInfo   属性。    
      由构造函数参数组成的   Arguments   属性,可用于实例化此对象。    
      布尔型   IsComplete   属性,指示对象是否由当前信息完全表示。    
      Invoke   方法,可用于创建所表示对象的实例。
     
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值