C#外部数据(类似于iOS Plist)
我正在寻找将简单数据结构外部化为人类可读文件的最佳实践。
我对 iOS 的 plist 功能有一些经验(我相信下面是类似 XML 的功能),我想找到类似的东西。
在 .NET 方面,.resx 似乎是可行的方法,但正如我所做的研究,每个人都提出本地化,而这些数据并不意味着本地化。 .resx 仍然是答案吗?
如果是这样,有没有办法获取所有 .resx 数据的字典结构而不是读取单个条目?我想知道条目数、所有键的数组、所有值的数组等。
I am looking for best practices on externalizing simple data structures into human readable files.
I have some experience with iOS's plist functionality (which I believe is XML-like underneith) and I'd like to find something similar.
On the .NET side .resx seems to be the way to go, but as I do research everyone brings up localization and this data is not meant to be localized. Is .resx still the answer?
If so, is there a way to get a dictionary structure of all the .resx data instead of reading a single entry? I'd like to know things like number of entries, an array of all the keys, an array of all the values, etc.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
鉴于我的建议,我会避免使用 XML。它被设计为易于解析。它很冗长,不是为了人类可读性而设计的。如果可以的话,避免尖括号税。
有 JSON。这是一个有用的替代方案。简单、易读、易解析。无尖括号税。这是一种选择。 YAML 是另一种(它是 JSON 的超集)。
有 LISP 风格的 S 表达式(另请参阅 维基百科)。您还可以使用 Prolog 风格的术语来构造您选择的数据结构(也很容易解析)。
还有老式的 DOS/Windows INI 文件。有多种工具可以解决这些问题,包括 .Net/CLR 实现。
您可以只合作 Apple 的 pList 格式< OS X 中的 /a> 。您可以使用它的 老式的“ASCII”(文本)表示法 或其 XML 表示。
您还可以(首选,恕我直言)编写自定义/“小”语言来专门满足您的需求。如今,流行语“du jour”是“特定领域语言”。我会避免使用 Visual Studio/C#/.Net 特定于域的语言工具,因为您得到的将是基于 XML 的。
Terrance Parr 出色的 ANTLR 可以说是语言构建的首选工具。它是用 Java 编写的,附带一个用于处理语法和解析树的 IDE,并且可以针对多种语言(Java、C#、Python、Objective-C、C/C++ 都是最新的。对 Scala 的一些支持为好吧,还有一些其他目标语言适用于旧版本,但完整性程度各不相同。)
Terrance Parr 的书同样出色:
Given my druthers, I'd avoid XML. It's designed to be easy to parse. It's verbose, it's not designed human readability. Avoid the angle-bracket tax if you can.
There's JSON. That's a useful alternative. Simple, easy to read, easy to parse. No angle-bracket tax. That's one option. YAML is another (it's a superset of JSON).
There's LISP-style S-expressions (see also wikipedia). You could also use Prolog-style terms to construct the data structures of your choice (also quite easy to parse).
And there's old-school DOS/Windows INI files. There's multiple tools out there for wrangling them, including .Net/CLR implementations.
You could just co-op Apple's pList format from OS X. You can use its old-school "ASCII" (text) representation or its XML representation.
You can also (preferred, IMHO) write a custom/"little" language to suit your needs specifically. The buzzword du jour for which, these days, is "domain-specific language". I'd avoid using the Visual Studio/C#/.Net domain-specific language facilities because what you get is going to be XML-based.
Terrance Parr's excellent ANTLR is arguably the tool of choice for language building. It's written in Java, comes with an IDE for working with grammars and parse trees, and can target multiple languages (Java, C#, Python, Objective-C, C/C++ are all up-to-date. There's some support for Scala as well. A few other target languages exist for older versions, in varying levels of completeness.)
Terrance Parr's books are equally excellent:
XML(任何格式,不仅仅是 resx)或 CSV 是常见的选择。只要 XML 是有效的 XML,就更容易在代码中使用。
查看 LINQ to XML ( http://msdn.microsoft.com/en-us /library/bb387098.aspx )开始读取 XML。
XML (any format, not just resx) or CSV are common choices. XML is easier to use in the code as long as it is valid XML.
Look into LINQ to XML ( http://msdn.microsoft.com/en-us/library/bb387098.aspx ) to get started on reading XML.