2

C# を使用して Windows フォーム アプリケーションで新しい設定ファイルを使用しようとしています。

古い設定ファイル (Settings1.settings) を削除し、新しい設定ファイル (Settings.settings) を作成した後。

設定ファイルを使用するコードの編集を開始すると、新しい設定ファイルが認識されていないことに気付きました。例:

ここに画像の説明を入力

当社が作成した名前空間から使用されているカスタム設定クラスがあり、競合が発生しています。コードを正しい設定ファイルに向けるにはどうすればよいですか?

4

3 に答える 3

4

行ったことを複製しようとすると、Settings.Designer.csファイルの名前空間がこれから取得されていることに気付きました(テストにはコンソールアプリを使用しています)。

namespace ConsoleApplication1.Properties {


    [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "10.0.0.0")]
    internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {

        private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));

        public static Settings Default {
            get {
                return defaultInstance;
            }
        }

        [global::System.Configuration.UserScopedSettingAttribute()]
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
        [global::System.Configuration.DefaultSettingValueAttribute("False")]
        public bool Test {
            get {
                return ((bool)(this["Test"]));
            }
            set {
                this["Test"] = value;
            }
        }
    }
}

namespace ConsoleApplication1 {


    [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "10.0.0.0")]
    internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {

        private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));

        public static Settings Default {
            get {
                return defaultInstance;
            }
        }

        [global::System.Configuration.UserScopedSettingAttribute()]
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
        [global::System.Configuration.DefaultSettingValueAttribute("False")]
        public bool Temp {
            get {
                return ((bool)(this["Temp"]));
            }
            set {
                this["Temp"] = value;
            }
        }
    }
}

名前空間がConsoleApplication1.PropertiesからConsoleApplication1に変更されたことに気付く場合は、新しい設定ファイルの名前空間に.Propertiesを追加すると、問題が解決するはずです。

于 2012-06-20T00:40:53.087 に答える
1

設定ファイルの名前空間を確認すると、次の2つのオプションがあります。

  1. .csファイルの先頭にあるusingをこの名前空間に追加します。

  2. 使用する前に、設定ファイルの名前空間全体を書き込んでください。

于 2012-06-19T23:39:35.970 に答える