c# - Can .NET load and parse a properties file equivalent to Java Properties class? -


Is there an easy way to read a property file in C #, in which each property is on a different line after which An equal sign is the value, such as the following:

  server name = prod-srv1 port = 8888 customproperty = a value  

In Java, property class This parsing handles easily:

  properties myProperties = new properties (); FileInputStream fis = New FileInputStream (new file ("CustomProps.properties")); MyProperties.load (financial institutions); Println (myProperties.getProperty ("server name")); Println (myProperties.getProperty ("CustomProperty"));  

I can easily load the file in C # and parse each row, but without easily parse the name of a key to get a property Designed to be equal to yourself? I found C # information always like XML, but this is an existing file that I do not control and I like to keep it in the current format because it will need more time to convert the other team into XML. Parsing it with

No, there is no built-in support for this.

Would you have to make your own "INIFILReader" something like that?

  var data = new dictionary & lt; String, string & gt; (); Data in Forward (File. ReadLeans (PATHHOFIFE)) Add (line split ('=') [0], string .join ("=", line split ('='). Skip (1) toArray ())); Console.WriteLine (data ["server name"]);  

Edit: Update to reflect Paul's comment


Comments