0

私は最近自分のソフトウェアに取り組んでいて、連想配列を格納するのが最善の方法は何だろうと思っています。

私が思いついた唯一のことは、次のようなことをすることです。

<add key="disks" value="C|1|10,D|2|20,E|1|5,Z|1|3"/>

しかし、これは私の設定ファイルの可読性をあまり提供しません。コンソールアプリケーションであるため、設定ファイルを読みやすくしたいと思います。

これは、app.configファイルで指定されたディスクのディスクスペースをチェックするプログラムを作成したが、ディスクごとに異なるしきい値が必要なためです。

どのようにそれを解決しますか?これが私の現在の設定ファイルの一部です。

<!-- DISK FEATURE SETTINGS -->
  <!-- Type 1 is threshold by percentage and type 2 is threshold by a certain limit -->
  <add key="threshold_type" value="1" />
  <add key="threshold_limit" value="0,1" />
  <!-- Space_type defines if you want to limit using kilobytes (1), megabytes (2) or gigabytes (3) if using threshold_type 2 -->
  <add key="space_type" value="3" />
  <!-- Put the disks here delimited by a comma like this: C,D,E -->
  <add key="disks" value="C,D,E,Z"/>
<!-- SERVICE FEATURE SETTINGS -->
  <!-- Put the services here delimited by a comma like this: C,D,E -->
  <add key="services" value="spooler,ekrn,RadeonPro Support Service,TeamViewer6"/>
  <!-- Put this on 1 if you want to log your output to a text file -->
  <add key="logging" value="1"/>

perfmonカウンターを使用してデータを取得し、それをテキストファイルに保存する、パフォーマンスカウンタープログラムにも同じ原則を使用したいと思います。

私は人々がここで少し私を助けてくれることを願っています:)

4

3 に答える 3

4

I suggesst you to create your own configuration section. Custom configuration gives more readability and type safety. Here are links to create custom configuration http://msdn.microsoft.com/en-us/library/2tw134k3.aspx and http://haacked.com/archive/2007/03/11/custom-configuration-sections-in-3-easy-steps.aspx (old one but easy to follow).

于 2012-07-27T05:33:48.197 に答える
1

標準の構成メカニズムがXMLシリアル化で機能する限り、App.configに辞書を格納するための最良の(そして、私見では賢明な)方法はList<KeyValuePair<K,V>>です。

于 2012-07-27T05:26:15.883 に答える
0

system.collectionまたはList<>のHashtableを使用することをお勧めします

以下は、ハッシュテーブルのいくつかのポインタです 。http: //www.dotnetperls.com/hashtable http://www.tutorialspoint.com/csharp/csharp_hashtable.htm

これがお役に立てば幸いです!! ありがとう :)

于 2014-06-12T10:56:07.947 に答える