類型轉換做誤 System.NotSupportedException: “TypeConverter”

來源:互聯網
上載者:User

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

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.