#眉標=Enterprise Library #副標=設計模型套件系列(13) #大標=設計好用的Application Block(下) #作者=文/圖 王寧疆 ===<反灰>============= private const string WebServiceUrlPropertyName = "url"; //存放XML Web Service網址的屬性名稱 [ConfigurationProperty(WebServiceUrlPropertyName)] //指定顯示在設定工具中的屬性名稱 public string WebServiceUrl //定義WebServiceUrl屬性 {   get { return (string)this[WebServiceUrlPropertyName]; } //讀取屬性值 set { this[WebServiceUrlPropertyName] = value; } //寫入屬性值 } private const string DictionaryIdPropertyName = "dictionaryId"; //存放Dictionary ID的屬性名稱 [ConfigurationProperty(DictionaryIdPropertyName)] //指定顯示在設定工具中的屬性名稱 public string DictionaryId //定義DictionaryId屬性 {   get { return (string)this[DictionaryIdPropertyName]; } //讀取屬性值 set { this[DictionaryIdPropertyName] = value; } //寫入屬性值 } ================ ===<反灰>============= public WordLookupApplicationBlock.IDictionaryProvider Assemble(IBuilderContext context, WordLookupApplicationBlock.Configuration.DictionaryProviderData objectConfiguration, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache) { WebServiceDictionaryProviderData castObjectConfiguration= (WebServiceDictionaryProviderData)objectConfiguration; WebServiceDictionaryProvider createdObject = new WebServiceDictionaryProvider(castObjectConfiguration.WebServiceUrl, castObjectConfiguration.DictionaryId); //依據指定的XML Web Service網址 //和DictionaryId建立負責查詢單字定義的Provider物件 return createdObject; //傳回建立好的Provider物件 } ================ ===<反灰>============= private void btnLookup_Click(object sender, EventArgs e) {   IDictionaryProvider provider = DictionaryProviderFactory.CreateDictionaryProvider(cbProvider.Text);//建立使用者指定的Provider string result = provider.Lookup(txtWord.Text); //命令Provider查詢使用者輸入的單字定義 txtResult.Text = result; //將查詢得到的單字定義顯示到畫面下方的TextBox控制項 } ================ ===<反灰>=============   
              ================ ===<反灰>============= WordLookupApplicationBlock.dll WordLookupApplicationBlock.Configuration.Design.dll ================