Is there a class like java.util.Properties?

B

Beorne

Is there a generic Properties class in C# like java.util.properties?
I'd like some class that I can easily write and read from a a file and
that constains <unique_string,string> pairs to be used as a
configuration or parameters or properties file.
I'm working on Compact Framework so I can't use serialization (sob ...)
 
J

Jon Skeet [C# MVP]

Beorne said:
Is there a generic Properties class in C# like java.util.properties?
I'd like some class that I can easily write and read from a a file and
that constains <unique_string,string> pairs to be used as a
configuration or parameters or properties file.
I'm working on Compact Framework so I can't use serialization (sob ...)

There isn't a built-in class as far as I'm aware, but it would be very
easy to write one - especially if you don't have many requirements
about escaping etc. I'd suggest making the file UTF-8 rather than
ISO-8859-1 as per Java, however - that way you only need to be able to
escape carriage return, line feed, space etc, rather than \uxxxx as
well.
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

Jon said:
I'd suggest making the file UTF-8 rather than
ISO-8859-1 as per Java, however - that way you only need to be able to
escape carriage return, line feed, space etc, rather than \uxxxx as
well.

1.5 can read XML in UTF-8 and 1.6 can read the key=val format
in UTF-8.

Arne
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

Beorne said:
Is there a generic Properties class in C# like java.util.properties?
I'd like some class that I can easily write and read from a a file and
that constains <unique_string,string> pairs to be used as a
configuration or parameters or properties file.
I'm working on Compact Framework so I can't use serialization (sob ...)

Or app config which is probably the true equivalent for
Java properties files.

I think the most .NET'ish way would be to create some code
that reads a XML file in traditional app config format.

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top