How to remove resource record from resx in C #?

I know how to programmatically retrieve and create resource records in a .resx file. I use ResourceWriterand ResourceReaderfor this approach. But now I want to clear some elements in my .resx file and want to delete them. How can i achieve this?

+3
source share
2 answers

Using ResXResourceReader and ResXResourceWriter classes.

Read your resx using a reader and submit it to the record, omitting the records you want to delete.

+6
source

, .

:

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();
            }
        }

, .

, , !

0

Source: https://habr.com/ru/post/1719698/


All Articles