开发者

C# External Data (similar to iOS Plist)

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 al开发者_开发知识库l the keys, an array of all the values, etc.


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:

  • The Definitive ANTLR Reference: Building Domain-Specific Languages
  • Language Implementation Patterns: Create Your Own Domain-Specific and General Programming Languages


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜