现在的位置: 首页 > 综合 > 正文

复制一个资源文件并带comment列

2012年10月13日 ⁄ 综合 ⁄ 共 891字 ⁄ 字号 评论关闭

            string resourceBackUpName = this.GetResourceBackUpName(resxFilePath);//back up the res file
            File.Copy(resxFilePath, resourceBackUpName);

 

            ResXResourceReader reader = new ResXResourceReader(resourceBackUpName);
            reader.UseResXDataNodes = true; // set it for get comments

            ResXResourceWriter writer = new ResXResourceWriter(resxFilePath);

            foreach (DictionaryEntry entry in reader)
            {
                ResXDataNode tmpNode = (ResXDataNode)entry.Value;

                AssemblyName[] assemblies = Assembly.GetExecutingAssembly().GetReferencedAssemblies();
                string theValue = tmpNode.GetValue(assemblies).ToString();

                ResXDataNode trimNode = new ResXDataNode(entry.Key.ToString(), theValue);
                trimNode.Comment =  tmpNode.Comment;

                writer.AddResource(trimNode);
            }
            reader.Close();
            writer.Close();

抱歉!评论已关闭.