/// <summary> /// 根据传入的Wordbook关键信息字符串生成字典实例 /// </summary> /// <param name="keyInfo">字典的关键信息组成的字符串</param> /// <returns>字典类实例</returns> public static BaseWordbook GetWordbookByString(string keyInfo) { if (String.IsNullOrEmpty(keyInfo)) { return(null); } //throw new ArgumentNullException("字典类名为空"); // 解析出字典类名字 int p = keyInfo.IndexOf(SeparatorSign.OtherSeparator); if (p < 0) { return(null); } //throw new ArgumentException("未定义字典类名"); keyInfo = keyInfo.Substring(p + 3, keyInfo.Length - p - 3); p = keyInfo.IndexOf(SeparatorSign.OtherSeparator); if (p < 0) { return(null); } BaseWordbook wordbook = WordbookStaticHandle.GetWordbook(keyInfo.Substring(0, p)); if (wordbook != null) { wordbook.ParameterValueComb = keyInfo.Substring(p + 3, keyInfo.Length - p - 3); } return(wordbook); }
private void wordbookTree_TreeDoubleClick(object sender, EventArgs e) { if (wordbookTree.CurrentBookInfo.TypeName != null) { _wordbook = WordbookStaticHandle.GetWordbook(wordbookTree.CurrentBookInfo.TypeName); // 用选中的字典初始化界面 InitializeEditBox(); } }
/// <summary> /// 在给定 Object 的一组属性值的情况下重新创建该对象 /// </summary> /// <param name="context"></param> /// <param name="propertyValues"></param> /// <returns></returns> public override object CreateInstance(ITypeDescriptorContext context, IDictionary propertyValues) { if (propertyValues == null) { throw new ArgumentNullException(MessageStringManager.GetString("NullParameter")); } BaseWordbook wordbook = WordbookStaticHandle.GetWordbook((string)propertyValues["WordbookName"]); wordbook.ExtraCondition = propertyValues["ExtraCondition"].ToString(); wordbook.SelectedStyleIndex = (int)propertyValues["SelectedStyleIndex"]; wordbook.MatchFieldComb = propertyValues["MatchFieldComb"].ToString(); wordbook.ParameterValueComb = propertyValues["ParameterValue"].ToString(); wordbook.CacheTime = (int)propertyValues["SelectedStyleIndex"]; return(wordbook); }
/// <summary> /// 将给定值转换为此转换器的类型 /// </summary> /// <param name="context"></param> /// <param name="culture"></param> /// <param name="value"></param> /// <returns></returns> public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { // 从String转成BaseWordbook类 string bookName = (string)value; if (bookName != null) { // 创建BaseWordbook实例 try { // 利用静态方法得到正确的字典类。无对应名称将返回null return(WordbookStaticHandle.GetWordbook(bookName)); } catch { throw;// new ArgumentException("参数不正确"); } } return(base.ConvertFrom(context, culture, value)); }