コード例 #1
0
        private Enumeration FindOrCreateFilterFunctionsEnumeration()
        {
            foreach (Enumeration enumeration in Project.Enumerations)
            {
                if (enumeration.GetAttributeValue("isFilterFunctionsEnumeration", NamespaceUri, false))
                {
                    return(enumeration);
                }
            }

            Enumeration e = Project.Enumerations.FirstOrDefault(_ => string.Equals(_.Name, "FilterFunction", StringComparison.OrdinalIgnoreCase) || string.Equals(_.Name, "FilterFunctions", StringComparison.OrdinalIgnoreCase));

            if (e != null)
            {
                return(e);
            }

            e           = new Enumeration();
            e.Name      = typeof(FilterFunctions).Name;
            e.Namespace = Project.DefaultNamespace;
            e.IsFlags   = Project.GetAttributeValue("createMultiValuedEnumeration", NamespaceUri, true);
            e.SetAttributeValue(PreferredPrefix, "isFilterFunctionsEnumeration", NamespaceUri, true);
            Project.Enumerations.Add(e);

            foreach (FilterFunctions value in ConvertUtilities.EnumEnumerateValues <FilterFunctions>())
            {
                EnumerationValue enumerationValue = new EnumerationValue();
                enumerationValue.Name = value.ToString();
                enumerationValue.SetAttributeValue(PreferredPrefix, "filterFunction", NamespaceUri, value);

                List <string> enumNames = ConvertUtilities.SplitEnumNames(value).ToList();
                if (enumNames.Count() > 1)
                {
                    if (!e.IsFlags)
                    {
                        continue;
                    }

                    enumerationValue.Value = ConvertUtilities.Concatenate(enumNames, " | ");
                }
                else
                {
                    enumerationValue.Value = ((int)value).ToString(CultureInfo.InvariantCulture);
                }

                enumerationValue.Value = ((int)value).ToString(CultureInfo.InvariantCulture);
                e.Values.Add(enumerationValue);
            }

            return(e);
        }