{"id":27453665,"url":"https://github.com/banban525/applicationregistries","last_synced_at":"2025-04-15T13:56:37.503Z","repository":{"id":26867497,"uuid":"30327792","full_name":"banban525/ApplicationRegistries","owner":"banban525","description":"ApplicaitonRegistries is a .NET library that will proxy the application's external settings.","archived":false,"fork":false,"pushed_at":"2018-12-20T11:02:19.000Z","size":1444,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-15T13:56:29.590Z","etag":null,"topics":["c-sharp","commandline-arguments","dotnet-framework","environment-variables","registry","windows"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/banban525.png","metadata":{"files":{"readme":"README.ja.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-02-04T23:49:50.000Z","updated_at":"2019-03-28T05:49:10.000Z","dependencies_parsed_at":"2022-07-25T16:48:20.118Z","dependency_job_id":null,"html_url":"https://github.com/banban525/ApplicationRegistries","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/banban525%2FApplicationRegistries","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/banban525%2FApplicationRegistries/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/banban525%2FApplicationRegistries/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/banban525%2FApplicationRegistries/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/banban525","download_url":"https://codeload.github.com/banban525/ApplicationRegistries/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249085485,"owners_count":21210267,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c-sharp","commandline-arguments","dotnet-framework","environment-variables","registry","windows"],"created_at":"2025-04-15T13:56:36.638Z","updated_at":"2025-04-15T13:56:37.489Z","avatar_url":"https://github.com/banban525.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"ApplicationRegistries\n======================\n\n[To Original(English)](https://github.com/banban525/ApplicationRegistries/blob/master/README.md)\n\nApplicaitonRegistries はアプリケーションの外部設定値のプロキシとなる.NETライブラリです。\n\n[![Build status](https://ci.appveyor.com/api/projects/status/a0004gg2p46y94ia?svg=true)](https://ci.appveyor.com/project/banban525/applicationregistries)\n[![NuGet version](https://badge.fury.io/nu/ApplicationRegistries.svg)](https://badge.fury.io/nu/ApplicationRegistries)\n[![NuGet Download](https://img.shields.io/nuget/dt/ApplicationRegistries.svg)](https://www.nuget.org/packages/ApplicationRegistries)\n[![MIT License](https://img.shields.io/github/license/banban525/ApplicationRegistries.svg)](LICENSE)\n\n## 説明\n\nWindowsアプリケーションを開発する場合、後で変更できるようにいくつかのパラメータが実装されています。\n例えば、スペックの影響を受けるパラメータであるタイムアウト時間や、PC全体のリソースを利用するパラメータであるポート番号があります。\n一般的な方法は次のとおりです。\n* 設定ファイル\n* 環境変数\n* コマンドライン引数\n* レジストリ (Windowsの場合)\n* アプリケーション構成ファイル(*.exe.config)\n\n自由に選択することができますが、これらはアプリケーションにとっては同じもので「外部設定値」です。\n\nただし、実装する方法はそれぞれ異なります。\nたとえば、コマンドライン引数パーザを自分で実装する必要があります。\nレジストリにはヌルチェックが必要です。\n気軽に使えるものではありません。\n\nまた、読み込み処理をさまざまな場所に実装すると、外部設定をリストするのが難しくなります。\nそれ以外に、実装方法が毎回同じにならないことがあります。\n\nApplicationRegistries は上記に挙げた「外部設定値」のプロキシとして機能します。\n簡単な使い方で、かつ、優先順位付きで、「外部設定値」を読み込むことができます。\nまた、「外部設定値」の一覧レポートを出力することもできます。\n\n## 使用例\n\n次のコードは使用例です。\n\n```csharp\n[ApplicationRegistry]\npublic interface ISettings\n{\n  /// \u003cSummary\u003e\n  /// Listen Port Number\n  /// \u003c/Summary\u003e\n  [DefaultValue(80)]\n  int PortNo { get; }\n\n  /// \u003cSummary\u003e\n  /// Backup to\n  /// \u003c/Summary\u003e\n  string BackupFolder { get; }\n}\n\nclass Program\n{\n  static void Main()\n  {\n    int portNo = ApplicationRegistry.Get\u003cISettings\u003e().PortNo;\n  }\n}\n\n```\n\n## 依存関係\n\nApplicationRegistries2.dll は、.NET Framework 4.5 のみに依存します。\n\n## インストール方法\n\n以下のコマンドでnugetからインストールできます。\n\n```\nPM\u003e Install-Package ApplicationRegistries\n```\n\n\n## 使い方\n\n1. ApplicationRegistries2.dll を参照します。\n2. 外部設定値に対応するインターフェイスを定義します。\n   なお、インターフェイスには次の制約があります。\n    * getプロパティのみを定義すること\n    * プロパティの型は次の型であること\n      * Int32\n      * string\n3. 外部設定値インターフェイスに属性[ApplicationRegistry]を付けます。\n4. `ApplicationRegistry.Get\u003cT\u003e()`を使って、プロパティにアクセスすることで外部設定値を読み込むことができます。\n  `T`には2で宣言したインターフェイス型を指定します。\n\nApplicationRegistriesはデフォルトでは次の優先順位で外部設定を読み込みます。\n* (1)コマンドライン引数\n* (2)環境変数\n* (3)レジストリ(HKCU)\n* (4)XMLファイル\n* (5)レジストリ(HKLM)\n\nなお、[ApplicationRegistry]属性の引数に、外部設定を読み込む場所を指定することで\n優先順位や有効・無効を設定できます。\n\n\n### コマンドライン引数\n\nデフォルトでは、以下のコマンドライン引数が読み込まれます。\n\n```\n--(インターフェイス名)_(プロパティ名)=\"設定値\"\n```\n\n例\n``` csharp\n  [ApplicationRegistry]\n  public interface ISettings\n  {\n    int PortNo {get;}\n  }\n```\n\n```\n--ISettings_PortNo=80\n```\n\n属性[CommandlineArgumentPrefix]と[CommandlineArgumentName]をつけることで\nインターフェイス名とプロパティ名を変更することができます。\n\n例\n``` csharp\n  [ApplicationRegistry]\n  [CommandlineArgumentPrefix(\"Settings\")]\n  public interface ISettings\n  {\n    [CommandlineArgumentName(\"ListenPort\")]\n    int PortNo {get;}\n  }\n```\n\n### 環境変数\n\nデフォルトでは、以下の環境変数が読み込まれます。\n\n```\nset (アセンブリ名)_(インターフェイス名)_(プロパティ名)=設定値\n```\n\n例\n``` csharp\n  // ApplicationRegistries.Sample.dll\n  [ApplicationRegistry]\n  public interface ISettings\n  {\n    int PortNo {get;}\n  }\n```\n\n```\nset ApplicationRegistries.Sample‗ISettings_PortNo=80\n```\n\n属性[EnvironmentVariablePrefix]と[EnvironmentVariableName]をつけることで\nアセンブリ名とインターフェイス名、プロパティ名を変更することができます。\n\n例\n``` csharp\n  [ApplicationRegistry]\n  [EnvironmentVariablePrefix(\"Settings\")]\n  public interface ISettings\n  {\n    [EnvironmentVariableName(\"ListenPort\")]\n    int PortNo {get;}\n  }\n```\n\n### レジストリ\n\nデフォルトでは、以下のレジストリが読み込まれます。\n\nHKCUの場合\n```\n[HKCU\\Software\\ApplicationRegistries\\(アセンブリ名)\\(インターフェイス名)]\n\"プロパティ名\"=型:設定値\n```\nHKLMの場合\n```\n[HKLM\\Software\\ApplicationRegistries\\(アセンブリ名)\\(インターフェイス名)]\n\"プロパティ名\"=型:設定値\n```\n\n例\n``` csharp\n  // ApplicationRegistries.Sample.dll\n  [ApplicationRegistry]\n  public interface ISettings\n  {\n    int PortNo {get;}\n  }\n```\n\n```\n[HKCU\\Software\\ApplicationRegistries\\ApplicationRegistries.Sample\\ISettings]\n\"PortNo\"=dword:00000050\n\n[HKLM\\Software\\ApplicationRegistries\\ApplicationRegistries.Sample\\ISettings]\n\"PortNo\"=dword:00000050\n```\n\n属性[RegistryKey]と[RegistryName]をつけることで\nインターフェイス名とプロパティ名を変更することができます。\n\n例\n``` csharp\n  [ApplicationRegistry]\n  [RegistryKey(@\"Software\\MyCompany\\MySoftware\")]\n  public interface ISettings\n  {\n    [RegistryName(\"ListenPort\")]\n    int PortNo {get;}\n  }\n```\n\n### XMLファイル\n\nデフォルトでは、次のXMLファイルが読み込まれます。\n\nファイルパス: (ApplicationRegistries2.dllのフォルダ)\\ApplicationRegisties.xml\n\n\n\n``` xml\n\u003c?xml version=\"1.0\" encoding=\"utf-8\" ?\u003e\n\u003cApplicationRegisties\u003e\n  \u003cインターフェイス名\u003e\n    \u003cプロパティ名\u003e設定値\u003c/プロパティ名\u003e\n  \u003c/インターフェイス名\u003e\n\u003c/ApplicationRegisties\u003e\n```\n\n例\n``` csharp\n  // ApplicationRegistries.Sample.dll\n  [ApplicationRegistry]\n  public interface ISettings\n  {\n    int PortNo {get;}\n  }\n```\n\n``` xml\n\u003c?xml version=\"1.0\" encoding=\"utf-8\" ?\u003e\n\u003cApplicationRegisties\u003e\n  \u003cISettings\u003e\n    \u003cPortNo\u003e80\u003c/PortNo\u003e\n  \u003c/ISettings\u003e\n\u003c/ApplicationRegisties\u003e\n```\n\n属性[XmlFile]と[XmlName]をつけることで\nファイル名やXMLの構造を指定することができます。\n\n例\n``` csharp\n  [ApplicationRegistry]\n  [XmlFile(@\".\\Settings.xml\", \"/Settings\")]\n  public interface ISettings\n  {\n    [XmlName(\"ListenPort\")]\n    int PortNo {get;}\n  }\n```\n\n``` xml\n\u003c?xml version=\"1.0\" encoding=\"utf-8\" ?\u003e\n\u003cSettings\u003e\n  \u003cListenPort\u003e80\u003c/ListenPort\u003e\n\u003c/Settings\u003e\n```\n\n### デフォルト値\n\n指定された外部設定値すべてでデータが取得できない場合に返すデフォルト値を属性[DefaultValue]で指定できます。\n\n``` csharp\n  [ApplicationRegistry]\n  public interface ISettings\n  {\n    [DefaultValue(80)]\n    int PortNo {get;}\n  }\n```\n\n### 外部設定の優先順位と無効化\n\n外部設定のデフォルトの優先順位は次の表の通りです。\n[ApplicationRegistry]の引数にキーを配列で指定することで、優先順位を変更したり、無効化することができます。\n\n\n| 外部設定          | デフォルトの優先順位 | 指定するキー                           |\n|------------------|---------------------|---------------------------------------|\n| コマンドライン引数 | 1                  | BuiltInAccessors.CommandlineArguments |\n| 環境変数          | 2                  | BuiltInAccessors.EnvironmenetVariable |\n| レジストリ(HKCU)  | 3                  | BuiltInAccessors.UserRegistry         |\n| XMLファイル       | 4                  | BuiltInAccessors.XmlFile              |\n| レジストリ(HKLM)  | 5                  | BuiltInAccessors.MachineRegistry      |\n\n``` csharp\n  [ApplicationRegistry(\n    BuiltInAccessors.CommandlineArguments,\n    BuiltInAccessors.EnvironmenetVariable,\n    BuiltInAccessors.UserRegistry,\n    BuiltInAccessors.MachineRegistry\n  )]\n  public interface ISettings\n  {\n    int PortNo {get;}\n  }\n```\n\n### ユーザー定義の外部設定\n\nアプリケーション固有のデータベースや設定ファイルから設定値を読み込みたい場合は、\n読み込み処理をユーザー定義することができます。\n\n1. IAccessor を実装した外部設定値読み込み用のでユーザー定義クラスを作成します\n2. `ApplicationRegistry.RegistCustomAccessor()`でユーザー定義クラスを登録します。\n   この時第1引数としてキーを指定します。\n``` csharp\n  ApplicationRegistry.RegistCustomAccessor(\"CUSTOM\", new CustomAccessor());\n```\n3. 2で登録したキーを属性[ApplicationRegistry]の引数に指定します。\n``` csharp\n  [ApplicationRegistry(\n    \"CUSTOM\",\n    BuiltInAccessors.CommandlineArguments,\n    BuiltInAccessors.EnvironmenetVariable,\n    BuiltInAccessors.UserRegistry,\n    BuiltInAccessors.MachineRegistry\n  )]\n  public interface ISettings\n  {\n    int PortNo {get;}\n  }\n```\n\n### レポート出力\n\n定義されたインターフェイスを読み込んでhtmlレポートを生成することができます。\nnugetで取得した場合は、パッケージマネージャコンソールまたはビルド後アクションにパスが通っています。\n\n``` powershell\n\u003e ApplicationRegistries2.Formatters.App.exe --input=\u003cyour assembly path\u003e --output=report.html\n```\n\nコマンドライン引数は次の通りです。\n\n```\n-i,--input    (必須) アセンブリファイルパス(カンマ区切り)\n-o,--output   (必須) 出力ファイルパス\n-f,--format   カスタムレポートテンプレートのファイルパス\n-t,--template デフォルトのレポートテンプレートファイルを出力します。そのパスを指定します。\n-h,-?,--help  ヘルプの表示\n```\n\n### レポートのカスタマイズ\n\n`ApplicationRegistries2.Formatters.App.exe` の `--template` オプションでデフォルトのレポートテンプレートを出力できます。\n\n``` powershell\n\u003e ApplicationRegistries2.Formatters.App.exe --template=\u003coutput file path\u003e\n```\n\n出力されたレポートテンプレートを変更し、`--format`オプションを指定することで、\nレポートのスタイルや形式を変更することができます。\n\n``` powershell\n\u003e ApplicationRegistries2.Formatters.App.exe --input=\u003cyour assembly path\u003e --output=report.html --format=\u003cmy template\u003e\n```\n\n### ユーザー定義の外部設定のレポート\n\nユーザー定義の外部設定をレポート化するために`IPropertyFormatter`を実装して、`ApplicationRegistries2.Formatters.App.exe`の\n`--input`オプションでアセンブリを指定する必要があります。\n\n\n\n\n## 開発方法\n\n1. フォークしてください ( https://github.com/banban525/ApplicationRegistries/fork )\n2. 機能ブランチを作ってください (git checkout -b my-new-feature)\n3. コミットしてください (git commit -am 'Add some feature')\n4. ブランチをプッシュしてください (git push origin my-new-feature)\n5. プルリクエストを送ってください\n\n\n## ライセンス\n\n[MIT](https://github.com/banban525/ApplicationRegistries/blob/master/LICENSE)\n\n## 開発者\n\n[banban525](https://github.com/banban525)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbanban525%2Fapplicationregistries","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbanban525%2Fapplicationregistries","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbanban525%2Fapplicationregistries/lists"}