System.Net.Http.PluralizerResourceConvention.GetResourceName C# (CSharp) Method

GetResourceName() public method

Gets the name of the resource corresponding to the given entity by pluralizing it if necessary.
public GetResourceName ( Type entityType ) : string
entityType System.Type
return string
		public string GetResourceName(Type entityType)
		{
			var resourceName = this.pluralizer.IsSingular(entityType.Name) ?
				this.pluralizer.Pluralize(entityType.Name) :
				entityType.Name;

			switch (this.format)
			{
				case PluralizerResourceFormat.PascalCase:
					return Char.IsUpper(resourceName[0]) ?
						resourceName : new string(new[] { Char.ToUpper(resourceName[0]) }.Concat(resourceName.Skip(1)).ToArray());
				case PluralizerResourceFormat.CamelCase:
					return Char.IsLower(resourceName[0]) ?
						resourceName : new string(new[] { Char.ToLower(resourceName[0]) }.Concat(resourceName.Skip(1)).ToArray());
				case PluralizerResourceFormat.LowerCase:
					return resourceName.ToLower();
				default:
					throw new NotSupportedException();
			}
		}
	}

Usage Example

Esempio n. 1
0
		public void WhenFormatLowerCase_ThenTurnsFirstLetterLowerCase()
		{
			var pluralizer = new PluralizerResourceConvention(
				PluralizationService.CreateService(new System.Globalization.CultureInfo("en-US")), PluralizerResourceFormat.CamelCase);

			Assert.Equal("helloWorlds", pluralizer.GetResourceName(typeof(HelloWorld)));
		}