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 方法,可用於建立所表示對象的執行個體。