Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. C# Equivalent to Java "Properties" Class

C# Equivalent to Java "Properties" Class

Scheduled Pinned Locked Moved C#
jsonquestioncsharpjavahtml
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    K L K
    wrote on last edited by
    #1

    Java's Properties class (http://java.sun.com/javase/6/docs/api/java/util/Properties.html[^]) is an easy way to serialize a bunch of properties to and from a file. I am trying to port a Java application that makes heavy use of this class, to C#. What is the easiest way to emulate this behavior? I thought about XML serialization, but that doesn't work because all the field names have to be specified in advance. Any ideas?

    C B 2 Replies Last reply
    0
    • K K L K

      Java's Properties class (http://java.sun.com/javase/6/docs/api/java/util/Properties.html[^]) is an easy way to serialize a bunch of properties to and from a file. I am trying to port a Java application that makes heavy use of this class, to C#. What is the easiest way to emulate this behavior? I thought about XML serialization, but that doesn't work because all the field names have to be specified in advance. Any ideas?

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      How about a Hashtable. The Java properties class extends Java's implementation of a hashtable, so why not use a Hashtable in C# also?

      Recent blog posts: * Introduction to LINQ to XML (Part 1) - (Part 2) - (part 3) My website | Blog

      K 1 Reply Last reply
      0
      • C Colin Angus Mackay

        How about a Hashtable. The Java properties class extends Java's implementation of a hashtable, so why not use a Hashtable in C# also?

        Recent blog posts: * Introduction to LINQ to XML (Part 1) - (Part 2) - (part 3) My website | Blog

        K Offline
        K Offline
        K L K
        wrote on last edited by
        #3

        Hey Colin, That's true, it does extend hashtable - but the real value of the Properties class comes in the utilities it provides for saving/loading that hashtable's contents to streams in different formats (XML, flat file, etc.) This capability is what I am looking for. If I don't find it I'll have to write it and post it here ;)

        1 Reply Last reply
        0
        • K K L K

          Java's Properties class (http://java.sun.com/javase/6/docs/api/java/util/Properties.html[^]) is an easy way to serialize a bunch of properties to and from a file. I am trying to port a Java application that makes heavy use of this class, to C#. What is the easiest way to emulate this behavior? I thought about XML serialization, but that doesn't work because all the field names have to be specified in advance. Any ideas?

          B Offline
          B Offline
          buchstaben
          wrote on last edited by
          #4

          using application/ user settings in c# is at least as easy as properties in java. however, c# settings are serialized in xml, whereas properties are not.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups