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 方法,可用于创建所表示对象的实例。