• Recent Questions
  • C#

    Prefix spaces for each line in a string

    My code generator requires to generate code with right indentation, so I need to prefix spaces for each line of a string. After google the world, there isn’t a out-of-box solution for me to use, finally I came up with my own solution:

    internal static string Indent(this string content, int level = 1) =>
        string.Join(Environment.NewLine, content
            .Split(new[] { "\r\n" }, StringSplitOptions.None)
            .Select(_ => $"{(_ == string.Empty ? string.Empty : new string(' ', level * 4))}{_}")
            .ToArray());
    

    Usage like this:

    var result = str.Indent();
    
    C#

    Use Roslyn to generate semantic code

    Scenario: I have made some utilities to generate C# code, however, I just utilize literal string with string.format, which is not good enough after Roslyn come out. So I tried to generate semantic code using Roslyn.

    More
  • Old Questions
  • Projects
  • UChainDb Client(ngx)

    Universal client for UChainDb http://app.uchaindb.com

    Detail

    Hidden Code Auto Gen(C#)

    Helper Generator to generate varies of hidden code which we shouldn't care about.

    Detail

    UAP Network

    wrapper for UAP protocol which is widely used in USSD channel of mobile service in china

    Detail

  • More Projects