3

我知道如何以编程方式在 .resx 文件中检索和创建资源条目。我正在使用ResourceWriterand theResourceReader方法。但现在我想清理 .resx 文件中的几个项目,并想删除它们。我怎样才能做到这一点?

4

2 回答 2

6

使用ResXResourceReaderResXResourceWriter类。

使用阅读器阅读您的 resx 并将其提供给编写器,省略您要删除的条目。

于 2009-10-09T09:18:56.523 回答
0

在我的工作中,我必须开发以从文化文件中删除标准文化文件中的内容。

代码是这样的:

private void ResolveConflicts()
        {
            using (var cultura = new ResXResourceReader(CulturaPath))
            using (var culturaCustom = new ResXResourceReader(CulturaCustomPath))
            {
                Resources = (from cc in culturaCustom.Cast<DictionaryEntry>()
                             where !(from c in cultura.Cast<DictionaryEntry>()
                                     select new { c.Key, c.Value })
                             .Contains(new { cc.Key, cc.Value })
                             select new Tuple<string, string>(
                                  cc.Key.ToString(),
                                  cc.Value.ToString())).ToList();
            }

            ReWriteCustomFile();
        }

        private void ReWriteCustomFile()
        {
            using (var writer = new ResXResourceWriter(CulturaCustomPath))
            {
                Resources.ForEach(r => writer.AddResource(r.Item1, r.Item2));

                writer.Generate();
                writer.Close();
            }
        }

使用此代码,它只记录在自定义文化中与默认值不同的内容。

我希望它有帮助,谢谢!

于 2017-10-09T16:08:05.527 回答