Top > CSharp > ちょこっとコード集

ちょこっとコード集 Edit

いつも忘れるラムダ式 Edit

http://csharp30matome.seesaa.net/article/129993518.html

cpp/hppの命名ルール変更時のコード Edit

Everything is expanded.Everything is shortened.
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 
 
 
 
 
 
 
-
|
-
|
|
-
|
!
|
|
-
|
|
|
|
|
-
|
|
|
|
|
|
|
|
|
|
|
|
|
!
|
|
|
-
|
-
|
!
|
!
!
|
|
|
-
|
|
!
|
!
!
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
 
namespace MemberPropertyNameChanger
{
    class Program
    {
        // memberValue_ -> mMemberValue
        static void Main(string[] args)
        {
            Exec(new DirectoryInfo(args[0]));
        }
 
        static void Exec(DirectoryInfo aDir)
        {
            // 各ファイル
            List<FileInfo> fileInfos = new List<FileInfo>();
            fileInfos.AddRange(aDir.GetFiles("*.cpp"));
            fileInfos.AddRange(aDir.GetFiles("*.hpp"));
            foreach (var fileInfo in fileInfos)
            {
                // オープン
                Console.WriteLine(fileInfo.FullName);
                string text = File.ReadAllText(fileInfo.FullName, Encoding.GetEncoding("shift_jis"));
                
                // 置き換え
                text = System.Text.RegularExpressions.Regex.Replace(
                    text,
                    @"(?<pre>[^a-zA-Z0-9])(?<name>[a-z][A-Za-z0-9]+)_(?<post>[^a-zA-Z0-9])",
                    new System.Text.RegularExpressions.MatchEvaluator(NameChange)
                    );
 
                // セーブ
                File.WriteAllText(fileInfo.FullName, text, Encoding.GetEncoding("shift_jis"));
            }
 
            // 子ディレクトリ
            foreach (var dirInfo in aDir.GetDirectories())
            {
                if (dirInfo.Name == ".svn")
                {
                    continue;
                }
                Exec(dirInfo);
            }
        }
 
        //MatchEvaluatorデリゲートメソッド
        private static string NameChange(System.Text.RegularExpressions.Match m)
        {
            string name = m.Groups["name"].Value;
            return m.Groups["pre"].Value + "m" + char.ToUpper(name[0]) + (1 < name.Length ? name.Substring(1) : "" ) + m.Groups["post"].Value;
        }
 
    }
}

Reload   New Lower page making Edit Freeze Diff Upload Copy Rename   Front page List of pages Search Recent changes Backup Referer   Help   RSS of recent changes
Last-modified: (4203d)