项目作者: stakx

项目描述 :
A .NET micro-library for converting "PascalCase" names to "camelCase".
高级语言: C#
项目地址: git://github.com/stakx/CamelCaser.git
创建时间: 2018-09-09T11:11:23Z
项目社区:https://github.com/stakx/CamelCaser

开源协议:MIT License

下载


CamelCaser

A small .NET library for converting identifiers to “camelCase”.

AppVeyor AppVeyor tests

  1. partial interface ICamelCaser { }
  2. nameof(ICamelCaser).ToLowerCamelCase();
  3. // => "camelCaser"

What could this be useful for?

The main purpose behind this library is to be able to automatically derive suitable variable names from type names e.g. in Reflection-based tools. The usual .NET conventions state that variable names should be in “camelCase”, while type names should be in “PascalCase”.

While this conversion is a no-brainer for humans, it’s actually made more complicated than one might realise at first by several .NET naming conventions:

  • For interface types whose name starts with an I, that I should be dropped: IFruitPickerfruitPicker (not iFruitPicker!)

  • When there are several initial upper-case characters, all but the last of them should be lower-cased: IDESettingsideSettings (not idesettings, nor idesEttings!)

  • … but not if all characters are in upper-case: IDEide (not idE!)

This library takes care of that transformation, so that you don’t have to.

How do I use it?

By importing the CamelCaser namespace, the following extension method becomes available:

  • string.ToLowerCamelCase():
    Converts the original string to “camelCase” according to the rules shown above.

But it doesn’t lower-case \ correctly!

If you think you’ve found a bug, please raise an issue so it can be looked into. (Make sure to mention the string that doesn’t get formatted as expected, along with your expectation of how it should have been formatted.)