Пример #1
0
        /// <summary>
        /// Provide a new implementation for finding a name for an OptionSet. If the
        /// OptionSet is not global, we want the name to be the concatenation of the Entity's
        /// name and the Attribute's name.  Otherwise, we can use the default implementation.
        /// </summary>
        public string GetNameForOptionSet(EntityMetadata entityMetadata, OptionSetMetadataBase optionSetMetadata, IServiceProvider services)
        {
            var name = GetPossiblyConflictedNameForOptionSet(entityMetadata, optionSetMetadata, services);

            while (EntityNames.Contains(name))
            {
                name += "_Enum";
            }
            return(OptionSetNames.TryGetValue(name.ToLower(), out var overriden) ? overriden : name);
        }
        /// <summary>
        /// Provide a new implementation for finding a name for an OptionSet. If the
        /// OptionSet is not global, we want the name to be the concatenation of the Entity's
        /// name and the Attribute's name.  Otherwise, we can use the default implementation.
        /// </summary>
        public string GetNameForOptionSet(EntityMetadata entityMetadata, OptionSetMetadataBase optionSetMetadata, IServiceProvider services)
        {
            var defaultName = DefaultService.GetNameForOptionSet(entityMetadata, optionSetMetadata, services);

            if (EntityNames.Contains(defaultName))
            {
                throw new Exception($"{defaultName} already exists as an entity.  This will cause a naming collision.");
            }

            if (UseDeprecatedOptionSetNaming)
            {
                return(defaultName);
            }
            // Ensure that the OptionSet is not global before using the custom implementation.
            if (optionSetMetadata.IsGlobal.HasValue && !optionSetMetadata.IsGlobal.Value)
            {
                // Find the attribute which uses the specified OptionSet.
                var attribute =
                    (from a in entityMetadata.Attributes
                     where a.AttributeType == AttributeTypeCode.Picklist &&
                     ((EnumAttributeMetadata)a).OptionSet.MetadataId == optionSetMetadata.MetadataId
                     select a).FirstOrDefault();

                // Check for null, since statuscode attributes on custom entities are not global,
                // but their optionsets are not included in the attribute metadata of the entity, either.
                if (attribute == null)
                {
                    if (optionSetMetadata.OptionSetType.GetValueOrDefault() == OptionSetType.Status && defaultName.EndsWith("statuscode"))
                    {
                        defaultName = string.Format(LocalOptionSetFormat, GetNameForEntity(entityMetadata, services), "StatusCode");
                    }
                }
                else
                {
                    // Concatenate the name of the entity and the name of the attribute
                    // together to form the OptionSet name.
                    return(string.Format(LocalOptionSetFormat, GetNameForEntity(entityMetadata, services),
                                         GetNameForAttribute(entityMetadata, attribute, services, CamelCaseClassNames)));
                }
            }
            return(UpdateCasingForGlobalOptionSets(defaultName, optionSetMetadata));
        }