示例#1
0
        /// <summary>
        /// 设置一个项的值
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        public bool SetItemValue(string key, object value)
        {
            if (!dictItemTypes.ContainsKey(key))
            {
                return(false);
            }
            lock (dictItemTypes[key])
            {
                if (null == value)
                {
                    //if (dictItemTypes[key].IsValueType)
                    //    return false;
                    dictItems[key] = value;
                    return(true);
                }


                if (dictItemTypes[key].IsAssignableFrom(value.GetType()))//value的类型是ItemType的子类
                {
                    dictItems[key] = value;
                    return(true);
                }

                if (JFTypeExt.IsExplicitFrom(dictItemTypes[key], value.GetType()))
                {
                    dictItems[key] = JFConvertExt.ChangeType(value, dictItemTypes[key]);
                    return(true);
                }
                return(false);
            }
        }
示例#2
0
        public bool EnqueList(string key, object element)
        {
            if (!dictListElementTypes.ContainsKey(key))
            {
                return(false);
            }
            lock (dictLists[key])
            {
                if (null == element)
                {
                    (dictLists[key] as IList).Add(element);
                    return(true);
                }
                if (dictListElementTypes[key].IsAssignableFrom(element.GetType()))
                {
                    (dictLists[key] as IList).Add(element);
                    return(true);
                }

                if (JFTypeExt.IsExplicitFrom(dictItemTypes[key], element.GetType()))
                {
                    (dictLists[key] as IList).Add(JFConvertExt.ChangeType(element, dictListElementTypes[key]));
                    return(true);
                }
                return(false);
            }
        }
示例#3
0
        bool UpdateView2IDs()//将界面绑定数据更新到对象中
        {
            if (null == methodItem)
            {
                return(true);
            }
            bool ret = true;

            do
            {
                string[] inParamNames = methodItem.Value.MethodInputNames;
                if (null != inParamNames && inParamNames.Length > 0)
                {
                    for (int i = 0; i < inParamNames.Length; i++)
                    {
                        if (string.IsNullOrEmpty(cbInputIDs[i].Text))
                        {
                            MessageBox.Show("输入参数\"" + inParamNames[i] + "\"未绑定数据项!\n");
                            return(false);
                        }
                        else
                        {
                            //类型转换判断
                            Type dstType = methodItem.Value.GetMethodInputType(inParamNames[i]);//方法的输入参数类型
                            Type srcType = null;
                            if (methodItem.TypePool.Keys.Contains(cbInputIDs[i].Text))
                            {
                                srcType = methodItem.TypePool[cbInputIDs[i].Text];//数池中变量的类型;
                            }
                            else
                            {
                                srcType = methodItem.OutterTypePool[cbInputIDs[i].Text];
                            }
                            if (dstType == srcType || JFTypeExt.IsImplicitFrom(dstType, srcType))//if (dstType == srcType ||dstType.IsAssignableFrom(srcType))//类型完全匹配
                            {
                                methodItem.SetInputID(inParamNames[i], cbInputIDs[i].Text);
                            }
                            else if (JFTypeExt.IsExplicitFrom(dstType, srcType))//可以进行强制转换
                            {
                                string msg = string.Format("参数项 {0}: 数据值类型\"{1}\" 需要强制转化为输入类型\"{2}\"\n是否继续绑定操作?", inParamNames[i], srcType.ToString(), dstType.ToString());
                                if (DialogResult.OK != MessageBox.Show(msg, "警告", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning))
                                {
                                    return(false);
                                }
                                methodItem.SetInputID(inParamNames[i], cbInputIDs[i].Text);
                            }
                            else if (!JFTypeExt.IsExplicitFrom(dstType, srcType)) //不可以进行强制转化的类型
                            {
                                string msg = string.Format("参数项 {0}: 数据值类型\"{1}\" 无法强制转化为输入类型\"{2}\"", inParamNames[i], srcType.ToString(), dstType.ToString());
                                MessageBox.Show(msg);
                                return(false);
                            }
                        }
                    }
                }
            } while (false);
            return(ret);
        }