Пример #1
0
        /// <inheritdoc />
        public string GetNameForAttribute(EntityMetadata entityMetadata, AttributeMetadata attributeMetadata, IServiceProvider services)
        {
            if (_mapper.GetNameFromMap(entityMetadata, attributeMetadata, services, out string value))
            {
                return(value);
            }

            value = _defaultService.GetNameForAttribute(entityMetadata, attributeMetadata, services);
            value = ModifyPublisher(value);
            return(value);
        }
Пример #2
0
        public void GetNameForAttribute_WhenNotUsingDisplayNames_ReturnsDefault()
        {
            namingService.GetNameForAttribute(Arg.Any <EntityMetadata>(), Arg.Any <AttributeMetadata>(), serviceProvider)
            .Returns("Name");
            parameters = new Dictionary <string, string> {
                { "UseDisplayNames", false.ToString() }
            };

            sut = new CodeNamingService(namingService, parameters);

            var result = sut.GetNameForAttribute(new EntityMetadata(), new AttributeMetadata(), serviceProvider);

            Assert.AreEqual(result, "Name");
        }
        public string GetNameForAttribute(EntityMetadata entityMetadata, AttributeMetadata attributeMetadata, IServiceProvider services)
        {
            if (entityMetadata == null)
            {
                throw new ArgumentNullException(nameof(entityMetadata));
            }
            if (attributeMetadata == null)
            {
                throw new ArgumentNullException(nameof(attributeMetadata));
            }

            if (removePublisherPrefix)
            {
                var noPrefixName = attributeMetadata.IsCustomAttribute == true?attributeMetadata.SchemaName.Substring(attributeMetadata.SchemaName.IndexOf("_", StringComparison.InvariantCulture) + 1) : attributeMetadata.SchemaName;

                var result = noPrefixName;
                var equal  = entityMetadata.Attributes.Where(x => noPrefixName == (x.IsCustomAttribute == true ? x.SchemaName.Substring(x.SchemaName.IndexOf("_", StringComparison.InvariantCulture) + 1) : x.SchemaName)).Select(x => new string[] { x.SchemaName, x.IsCustomAttribute == true ? x.SchemaName.Substring(x.SchemaName.IndexOf("_", StringComparison.InvariantCulture) + 1) : x.SchemaName }).ToArray();
                if (equal.Length > 1)
                {
                    for (int i = 0; i < equal.Length; i++)
                    {
                        if (equal[i][0] == attributeMetadata.SchemaName)
                        {
                            result = equal[i][1] + (i + 1);
                            break;
                        }
                    }
                }
                if (GetNameForEntity(entityMetadata, services) == noPrefixName)
                {
                    result += "_";
                }
                return(result);
            }
            else
            {
                return(namingService.GetNameForAttribute(entityMetadata, attributeMetadata, services));
            }
        }
 public string GetNameForAttribute(EntityMetadata entityMetadata, AttributeMetadata attributeMetadata, IServiceProvider services)
 {
     return(namingService.GetNameForAttribute(entityMetadata, attributeMetadata, services));
 }