Exemplo n.º 1
0
        /// <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);
        }
Exemplo n.º 2
0
 private void wordbookTree_TreeDoubleClick(object sender, EventArgs e)
 {
     if (wordbookTree.CurrentBookInfo.TypeName != null)
     {
         _wordbook = WordbookStaticHandle.GetWordbook(wordbookTree.CurrentBookInfo.TypeName);
         // 用选中的字典初始化界面
         InitializeEditBox();
     }
 }
Exemplo n.º 3
0
        /// <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);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 通过字典名称获取对应的字典类实例
        /// </summary>
        /// <param name="name">字典类的类名(全称或分类名+字典名)</param>
        /// <returns>类名正确,返回相应实例,否则报异常</returns>
        public static BaseWordbook GetWordbook(string name)
        {
            if (String.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException(MessageStringManager.GetString("NullParameterName"));
            }
            // 用Assembly.LoadFrom()需要解决不同应用程序域的问题,
            // 现在用此方式得到字典类的程序集,并进行反射处理。
            // 目前还不清楚这样做对性能有何影响,如果不行的话,只能还采用硬编码的方式
            Type bookType = null;

            if (m_WordbookAssembly == null)
            {
                Assembly[] assemlys = AppDomain.CurrentDomain.GetAssemblies();
                foreach (Assembly assembly in assemlys)
                {
                    //MessageBox.Show(assembly.GetName().Name);
                    // 通过比较Assembly的名称得到字典类的程序集
                    if (assembly.GetName().Name == "DrectSoft.Basic.Wordbook")
                    {
                        m_WordbookAssembly = assembly;
                        break;
                    }
                }
            }

            bookType = m_WordbookAssembly.GetType(ConvertBookNameToFullName(name));

            if (bookType == null)
            {
                //MessageBox.Show("Could not found the wordbook");
                return(null);
            }
            else
            {
                BaseWordbook result = (BaseWordbook)System.Activator.CreateInstance(bookType);;
                result.CacheTime = 0;
                return(result);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// 将给定值对象转换为指定的类型
        /// </summary>
        /// <param name="context"></param>
        /// <param name="culture"></param>
        /// <param name="value"></param>
        /// <param name="destinationType"></param>
        /// <returns></returns>
        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
        {
            // 将BaseWordbook类转成String或InstanceDescriptor
            BaseWordbook wordbook = value as BaseWordbook;

            if (wordbook != null)
            {
                // 转成String
                if ((destinationType == typeof(string)))
                {
                    return((wordbook).ToString());
                }
                // 转成InstanceDescriptor(从设计界面保存到Designer文件时需要)
                if ((destinationType == typeof(InstanceDescriptor)))
                {
                    object[] properties = new object[5];
                    Type[]   types      = new Type[5];
                    // FilterFields
                    types[0]      = typeof(string);
                    properties[0] = wordbook.MatchFieldComb;
                    // SelectedStyleIndex
                    types[1]      = typeof(int);
                    properties[1] = wordbook.SelectedStyleIndex;
                    // ParameterValues
                    types[2]      = typeof(string);
                    properties[2] = wordbook.ParameterValueComb;
                    // ExtraCondition
                    types[3]      = typeof(string);
                    properties[3] = wordbook.ExtraCondition;
                    // CacheTime
                    types[4]      = typeof(int);
                    properties[4] = wordbook.CacheTime;

                    //object[] properties = new object[1];
                    //Type[] types = new Type[1];
                    ////// FilterFields
                    //types[0] = typeof(Collection<string>);
                    //Collection<string> filters = new Collection<string>();
                    //filters.Add("aa");
                    //properties[0] = new Collection<string>(filters);

                    //object[] properties = new object[3];
                    //Type[] types = new Type[3];
                    ////// FilterFields
                    //types[0] = typeof(Collection<string>);
                    ////Collection<string> filters = new Collection<string>(wordbook.FilterFields);
                    //properties[0] = new Collection<string>();
                    //((Collection<string>)properties[0]).Add("czydm");
                    //((Collection<string>)properties[0]).Add("wb");
                    //((Collection<string>)properties[0]).Add("py");

                    //// SelectedStyleIndex
                    //types[1] = typeof(int);
                    //properties[1] = wordbook.SelectedStyleIndex;
                    //// ExtraCondition
                    //types[2] = typeof(string);
                    //properties[2] = wordbook.ExtraCondition;
                    // 得到构造函数信息
                    ConstructorInfo ci = wordbook.GetType().GetConstructor(types);
                    return(new InstanceDescriptor(ci, properties));
                }
            }
            // 基类的ConvertTo()必须调用
            return(base.ConvertTo(context, culture, value, destinationType));
        }