美文网首页
Cocos2d-JS 自动修复代码遗漏new问题

Cocos2d-JS 自动修复代码遗漏new问题

作者: 2b75747cf703 | 来源:发表于2017-06-02 09:10 被阅读30次
    首字母小写会自动转换为new对应的首字母大写类对象

    native平台开发不new也能正常运行,导致了开发过程中很多代码被遗漏了new,web平台上就悲剧了。

    using System.IO;
    using System.Text.RegularExpressions;
    
    namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                var files = Directory.GetFiles(@"C:\Users\664301573\Desktop\xxx\Client\src", "*", SearchOption.AllDirectories);
                foreach (var path in files)
                {
                    var text = File.ReadAllText(path);
    
                    text = Regex.Replace(text, @"(\w*)(\s*)((ccui|cc|ccs)\.[A-Z]\w+\s*\()", (match) =>
                    {
                        if(match.Groups[1].Value != "new")
                            return match.Groups[1].Value + match.Groups[2].Value + "new " + match.Groups[3].Value;
    
                        return match.Value;
                    });
    
                    File.WriteAllText(path, text);
                }
            }
        }
    }
    
    替换效果图

    相关文章

      网友评论

          本文标题:Cocos2d-JS 自动修复代码遗漏new问题

          本文链接:https://www.haomeiwen.com/subject/jvbyfxtx.html