Saving configuration items to .net

I have a set of configuration items that I need to save in a "human readable" file. These elements are in a hierarchy:

Device 1
   Name
   Channel 1
     Name
     Size
     ...
   Channel n
     Name
...
Device m
   Name
   Channel 1

Each of these elements can be stored in a dictionary with a string key and value. They can also be in the / DTO structure.

I do not need a file format if it is human readable. It can be XML or it can have something more than the INI format

[Header]
  Key = value
  Key2 = value
...

Is there a way to minimize the amount of boiler plate code that I would need to write to control the storage / reading of configuration items?

(DTO)/ ( XML ?)

?

: , , . app.config.

+3
8

FileHelpers. - , , Save(). ORM .

+1
+3

, XmlSerializer NetDataContractSerializer XML. NetDataContractSerializer, , XmlSerializer, , , , . , , , , .

app.config , ConfigSections .

+2

JSON, , XML.

JSON.Net James Netwon-King:

Product product = new Product();    
product.Name = "Apple";    
product.Expiry = new DateTime(2008, 12, 28);    
product.Price = 3.99M;    
product.Sizes = new string[] { "Small", "Medium", "Large" };    

string json = JavaScriptConvert.SerializeObject(product);
//{
//  "Name": "Apple",
//  "Expiry": new Date(1230422400000),
//  "Price": 3.99,
//  "Sizes": [
//    "Small",
//    "Medium",
//    "Large"
//  ]
//}   

Product deserializedProduct = JavaScriptConvert.DeserializeObject<Product>(json);

JSON.Net .

+2

, app.config, XML, .NET System.Configuration namesapce.

: http://geekswithblogs.net/akraus1/articles/64871.aspx

+1

( , !), System.Xml / XML . , , XML- , .

System.Configuration, .

0

DataSet DataTables , , - DataSet.WriteXML(), .

, , DataSet.ReadXML(), , .

, :

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<!--****************************************************************
 Config File: FileToExcel_test.cfg
      Author: Ron Savage
        Date: 06/20/2008

 Description: 
 File to test parsing a file into an Excel workbook.

 Modification History: 
 Date       Init Comment
 06/20/2008 RS   Created.
******************************************************************-->

<!--********************************************************************
 Global Key Definitions
********************************************************************-->
   <config key="sqlTimeout"      value="1800"/>
   <config key="emailSMTPServer" value="smtp-server.austin.rr.com"/>
   <config key="LogFile"         value="FiletoExcel_test_{yyyy}{mm}{hh}.log"/>
   <config key="MaxEntries"      value="1"/>

<!--********************************************************************
 Delimiter Configurations
********************************************************************-->
   <config key="pipe"           value="|"/>


<!--********************************************************************
 Source / Target Entries
********************************************************************-->
   <config key="source_1"  value="FILE, c:\inetpub\ftproot\filetoexcel.txt, pipe, , , , , "/>
   <config key="target_1"  value="XLS, REPLACE, c:\inetpub\ftproot\filetoexcel1.xls, , , , , , , ,c:\inetpub\ftproot\filetoexcel_template.xls, ,3"/>
   <config key="notify_1"  value="store_error, store_success"/>
</configuration>

DataSet, . .

0

, XML - , , ADO.NET DataSet, , , .

As far as its readability is concerned, it follows: if it just needs to be a human-readable person (and not a change in the person who, in my opinion, is what you describe here), I would build the XSLT transform and use it it should create HTML version of the configuration data whenever I wrote XML. This gives you subtle control over the visual presentation of the data, as you might ask.

0
source

Source: https://habr.com/ru/post/1697960/


All Articles