public static EnumTypePropertyDescription FromEnumTypeName(string enumTypeName)
		{
			if (string.IsNullOrEmpty(enumTypeName))
				throw new ArgumentNullException("enumTypeName");

			Type type = Type.GetType(enumTypeName);

			EnumTypePropertyDescription result = null;

			if (type != null)
			{
				EnumItemDescriptionList itemDespList = EnumItemDescriptionAttribute.GetDescriptionList(type);

				result = new EnumTypePropertyDescription();

				result.EnumTypeName = enumTypeName;

				foreach (EnumItemDescription itemDesp in itemDespList)
				{
					EnumItemPropertyDescription eipd = new EnumItemPropertyDescription();

					eipd.Value = itemDesp.ShortName.IsNotEmpty() ? itemDesp.ShortName : itemDesp.EnumValue.ToString();
					eipd.Text = itemDesp.Description.IsNotEmpty() ? itemDesp.Description : itemDesp.Name;

					result.Items.Add(eipd);
				}
			}

			return result;
		}
        public static EnumTypePropertyDescription FromEnumTypeName(string enumTypeName)
        {
            if (string.IsNullOrEmpty(enumTypeName))
            {
                throw new ArgumentNullException("enumTypeName");
            }

            Type type = Type.GetType(enumTypeName);

            EnumTypePropertyDescription result = null;

            if (type != null)
            {
                EnumItemDescriptionList itemDespList = EnumItemDescriptionAttribute.GetDescriptionList(type);

                result = new EnumTypePropertyDescription();

                result.EnumTypeName = enumTypeName;

                foreach (EnumItemDescription itemDesp in itemDespList)
                {
                    EnumItemPropertyDescription eipd = new EnumItemPropertyDescription();

                    eipd.Value = itemDesp.ShortName.IsNotEmpty() ? itemDesp.ShortName : itemDesp.EnumValue.ToString();
                    eipd.Text  = itemDesp.Description.IsNotEmpty() ? itemDesp.Description : itemDesp.Name;

                    result.Items.Add(eipd);
                }
            }

            return(result);
        }
Exemplo n.º 3
0
        internal static EnumTypePropertyDescription GenerateEnumTypePropertyDescription(DropdownPropertyDataSourceConfigurationElement config)
        {
            EnumTypePropertyDescription result = new EnumTypePropertyDescription();

            result.EnumTypeName = config.Name;

            DropDownList dr = new DropDownList();

            dr.DataTextField  = config.BindingText;
            dr.DataValueField = config.BindingValue;
            dr.DataSource     = GenerateDropDownListSourceByConfiguration(config);
            dr.DataBind();

            foreach (ListItem item in dr.Items)
            {
                result.Items.Add(new EnumItemPropertyDescription(item));
            }

            return(result);
        }
        internal static EnumTypePropertyDescription GenerateEnumTypePropertyDescription(DropdownPropertyDataSourceConfigurationElement config)
        {
            EnumTypePropertyDescription result = new EnumTypePropertyDescription();
            result.EnumTypeName = config.Name;

            DropDownList dr = new DropDownList();
            dr.DataTextField = config.BindingText;
            dr.DataValueField = config.BindingValue;
            dr.DataSource = GenerateDropDownListSourceByConfiguration(config);
            dr.DataBind();

            foreach (ListItem item in dr.Items)
                result.Items.Add(new EnumItemPropertyDescription(item));

            return result;
        }
Exemplo n.º 5
0
        private List <EnumTypePropertyDescription> CollectEnumDescriptions()
        {
            Dictionary <string, EnumTypePropertyDescription> enumDespDict = new Dictionary <string, EnumTypePropertyDescription>();

            foreach (string enumParams in PredefinedEnumTypes)
            {
                EnumTypePropertyDescription etpd = EnumTypePropertyDescription.FromEnumTypeName(enumParams);

                if (etpd != null)
                {
                    enumDespDict.Add(etpd.EnumTypeName, etpd);
                }
            }

            foreach (PropertyValue pv in this.Properties)
            {
                if (pv.Definition.DataType == PropertyDataType.Enum && string.IsNullOrEmpty(pv.Definition.EditorParams) == false)
                {
                    string editorParamName = pv.Definition.EditorParams;
                    if (Regex.IsMatch(pv.Definition.EditorParams, @"\{[^{}]*}") == true)
                    {
                        try
                        {
                            EditorParamsDefine editorParams = JSONSerializerExecute.Deserialize <EditorParamsDefine>(pv.Definition.EditorParams);
                            editorParamName = editorParams.EnumTypeName;
                            //将配置文件里的数据源转换成下拉列表数据源
                            if (editorParams.ContainsKey("dropDownDataSourceID") == true)
                            {
                                string sourceID = editorParams["dropDownDataSourceID"];
                                if (PropertyEditorHelper.AllDropdownPropertyDataSource.ContainsKey(sourceID) == true)
                                {
                                    EnumTypePropertyDescription etpd = PropertyEditorHelper.GenerateEnumTypePropertyDescription(PropertyEditorHelper.AllDropdownPropertyDataSource[sourceID]);
                                    if (etpd != null)
                                    {
                                        enumDespDict.Add(etpd.EnumTypeName, etpd);
                                    }
                                }
                            }
                        }
                        catch (Exception)
                        {   //这里吃掉异常,主要原因是兼容老已上线的流程配置文件
                            editorParamName = pv.Definition.EditorParams;
                        }
                    }

                    if (string.IsNullOrEmpty(editorParamName) == false)
                    {
                        if (enumDespDict.ContainsKey(editorParamName) == false)
                        {
                            EnumTypePropertyDescription etpd = EnumTypePropertyDescription.FromEnumTypeName(editorParamName);

                            if (etpd != null)
                            {
                                enumDespDict.Add(etpd.EnumTypeName, etpd);
                            }
                        }
                    }
                }
            }

            List <EnumTypePropertyDescription> result = new List <EnumTypePropertyDescription>();

            foreach (KeyValuePair <string, EnumTypePropertyDescription> kp in enumDespDict)
            {
                result.Add(kp.Value);
            }

            return(result);
        }